Relative Content

Tag Archive for typescriptenumsmapped-types

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 […]