I am trying to use an integer Enum as a key for an object type and it generates the error I included in the comments:
enum Enum {
first = 1,
second = 2,
third = 3,
}
type EnumAsKey = {
[key in Enum]: string; //<-- Type 'Enum' is not assignable to type 'string'
};
Shouldn't Enum be assignable to type number
and can't a number be used as an index here?
How do I achieve this?
I have also tried:
[key: Enum] <- An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type.
[key: typeof Enum[keyof typeof Enum]] <-- Type 'Enum' is not assignable to type 'string'
Related, but this solution only appears to work when the enum is of strings: How to use enum as index key type in typescript?