Enums in TypeScript
From the TypeScript cheat sheet ยท Basic Types ยท verified Jul 2026
Enums
Named constants with numeric or string values
typescript
enum Direction {
Up, // 0
Down, // 1
Left, // 2
Right, // 3
}
enum Status {
Active = "ACTIVE",
Inactive = "INACTIVE",
}
const dir: Direction = Direction.Up;๐ก String enums are preferred โ they are readable in logs and don't have reverse mapping overhead
โก Use const enum to inline values at compile time โ zero runtime cost
๐ Many teams prefer "as const" objects over enums โ they are simpler and tree-shakable
๐ข keyof typeof MyEnum gives you a union of the enum key names as strings
enumconst-enum