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 keyof typeof Animals
:
type AnimalsToMappedType = {
[K in (keyof typeof Animals)]: K
}
The result is:
type AnimalsToMappedType = {
CAT: "CAT";
DOG: "DOG";
PARROT: "PARROT";
SHEEP: "SHEEP";
SALMON: "SALMON";
}
QUESTION
What are the parenthesis doing that removes readonly [x: number]: number;
?
5