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
Yes. Just type
let layer:{[key in keyof typeof MyEnum]: any}
The keyof
keyword is available since Typescript 2.1. See the TypeScript documentation for more details.
Using only keyof
for enums wouldn't work (you'd get the keys of the enum
type and not the enum constants), so you have to type keyof typeof
.