Why does `[K in (keyof typeof SomeNumericEnum) as typeof SomeNumericEnum[K]]` result in the actual numerical index, rather than just `number`?
Given the following enum:
Why does adding parenthesis remove ‘readonly [x: number]: number;’ from this type?
enum Animals { CAT, DOG, PARROT, SHEEP, SALMON } The following type: type AnimalsToMappedType = { [K in keyof typeof Animals]: K } Results in: type AnimalsToMappedType = { readonly [x: number]: number; readonly CAT: “CAT”; readonly DOG: “DOG”; readonly PARROT: “PARROT”; readonly SHEEP: “SHEEP”; readonly SALMON: “SALMON”; } But if you add parenthesis around […]
Converting an Enum to a Mapped type in typescript: How/why does this work?
The Problem
Converting an Enum to a Mapped type in typescript: How/why does this utility function work?
The Problem