Issue
The question is can enum be used as a key type instead of only "number" or "string" ? Currently it seems like the only possible declaration is x:{[key:number]:any} where key can be of type "number" or "string". Is it possible to make something like in this example:
Example:
enum MyEnum
{
First,
Second
}
var layer:{[key:MyEnum]:any};
Solution
Since 2018, there is an easier way in Typescript, without using keyof typeof
:
let layer: { [key in MyEnum]: any}
To not have to include all keys:
let layer: { [key in MyEnum]?: any}
Answered By - Hugo Elhaj-Lahsen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.