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

More TypeScript tasks

Back to the full TypeScript cheat sheet