String Enums

TypeScript 2.4 now allows enum members to contain string initializers.

  1. enum Colors {
  2. Red = "RED",
  3. Green = "GREEN",
  4. Blue = "BLUE",
  5. }

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".