0

How can I convert a type union into an array of values?

I'm trying to create this:

const sportsArray = ['Football', 'Baseball', 'Hockey'];

...from this:

type Sports = 'Football' | 'Baseball' | 'Hockey';
Jonathan.Brink
  • 23,757
  • 20
  • 73
  • 115
  • does this help? https://stackoverflow.com/questions/44480644/typescript-string-union-to-string-array – Abhilash Aug 19 '20 at 18:27
  • 1
    The answer to that question is a bit confusing to me, as it seems like it's going from array -> type, whereas I'm trying to go from type -> array – Jonathan.Brink Aug 19 '20 at 18:28
  • 1
    The answer linked by @Abhilash states it is not possible to do what you are trying to accomplish. https://github.com/Microsoft/TypeScript/issues/13298 proposal was declined as it would not leave the type system fully erasable. – Lesiak Aug 19 '20 at 18:33

0 Answers0