String Enums
TypeScript 2.4 now allows enum members to contain string initializers.
enum Colors {
Red = "RED",
Green = "GREEN",
Blue = "BLUE",
}
The caveat is that string-initialized enums can’t be reverse-mapped to get the original enum member name.In other words, you can’t write Colors["RED"]
to get the string "Red"
.