Snippet:
enum Color {
RED = 0,
GREEN
}
const myMap = new Map<Color, string>([
[Color.GREEN, "foo"],
[Color.RED, "bar"]
])
const red_s = "RED"
const myColor: Color = red_s as unknown as Color
console.log(`myColor ${myColor}`)
const mapVal = myMap.get(myColor)
if (mapVal) {
console.log(`mapVal ${mapVal}`)
}
else {
console.log(`no mapVal found`)
}
Why is the enum myColor not found in myMap?
How can I use the enum as a key for the map?
Color.GREENis1andColor.REDis0, they're not the strings"GREEN"and"RED". You'll see that if you log these values or yourMap.Color[Color.RED]is"RED"