How does TypeScript handle enums?
Answer
Enums in TypeScript provide a way to define a set of named constants, either numeric or string-based.
enum Direction {
Up = 1,
Down,
Left,
Right,
}
console.log(Direction.Up); // 1
console.log(Direction[2]); // Down
enum Color {
Red = "RED",
Green = "GREEN",
Blue = "BLUE",
}
console.log(Color.Red); // "RED"