I have enum:
enum DemoEnum {
a = 'EnumValueA',
b = 'EnumValueB'
}
I would like to create type Type = 'EnumValueA' | 'EnumValueB' from my enum values.
How can I do this?
My current state is type of "keys":
type Type = keyof typeof DemoEnum // 'a' | 'b'
For example I would like to use it in my react props.
type Props {
value: 'EnumValueA' | 'EnumValueB',
}
In case of usage <MyComponent value='EnumValueA'>
type Props {
value: DemoEnum,
}
I am getting an error Type .. is not assignable to DemoEnum
DemoEnumas the type, since it is a subtype of the union you're looking for.