Given the following enum:
enum Animals {
CAT,
DOG,
PARROT,
SHEEP,
SALMON
}
The following mapped type:
type AnimalsToMappedType = {
[K in (keyof typeof Animals) as typeof Animals[K]]: K
}
Results in:
type AnimalsToMappedType = {
0: "CAT";
1: "DOG";
2: "PARROT";
3: "SHEEP";
4: "SALMON";
}
QUESTION
Given that:
typeof Animals['DOG'] === 'number`
Why does [K in (keyof typeof Animals) as typeof Animals[K]]
result in the actual numerical index, rather than just number
?