Seeking to retrieve the id
based on the animal's name
:
enum Animals {
Cat = 1,
Dog, // 2
}
const name: string = "Cat";
const id: number = Animals[name] // Element implicitly has an 'any' type because index expression is not of type 'number'.
Cited from https://basarat.gitbooks.io/typescript/docs/enums.html#enums-and-strings
enum Tristate {
False,
True,
Unknown
}
console.log(Tristate["False"]); // 0
Issue - How can I obtain 1
linked with Cat