So I know that keyof typeof <enum> returns a type of all possible keys of enum, such that given
enum Season{
WINTER = 'winter',
SPRING = 'spring',
SUMMER = 'summer',
AUTUMN = 'autumn',
}
let x: keyof typeof Season;
is equivalent to
let x: 'WINTER' | 'SPRING' | 'SUMMER' | 'AUTUMN';
my question is how do I get a type that will be equivalent to one of the possible values of the enum, for example:
let x: 'winter' | 'spring' | 'summer' | 'autumn';
Seasonis equal to the union of the enum object's values, althoughSeasonis a subtype of'winter' | 'spring' | 'summer' | 'autumn'. DoesSeasonnot work for you? (e.g.,declare let s: Season; let x: 'winter' | 'spring' | 'summer' | 'autumn' = s;)let x: Season = 'winter';let x: Season = Season.WINTERwhich is essentially the same thing? Even if you could dolet x: Magic<Season> = 'winter', what would you do with it? I want to see more of a use case here