Let's say I have a type, for example:
type Contact = "email" | "phone"
Is there a way to convert the type Contact
to a list of strings ["email", "phone"]
, so I could use that list at runtime, as an ordinary javascript value?
Let's say I have a type, for example:
type Contact = "email" | "phone"
Is there a way to convert the type Contact
to a list of strings ["email", "phone"]
, so I could use that list at runtime, as an ordinary javascript value?
You can't go from type to list, but you can go the other way around. You could do something like this:
const CONTACTS = ['email', 'phone'] as const
type Contact = typeof CONTACTS[number]
Then you can manage that list in only one place