enum

Declares a named set of numeric or string constants.

Since TS 1.0 Spec ↗

Syntax

enum Name { Member = value }

Examples

enum Direction {
  Up,
  Down,
  Left,
  Right,
}

const d: Direction = Direction.Up; // 0
enum Status {
  Active = 'ACTIVE',
  Closed = 'CLOSED',
}

Notes

Numeric enums auto-increment from 0 and create a reverse mapping; string enums do not. Enums emit a runtime object unless declared `const enum`, which inlines values. Consider union string literal types as a lighter alternative when no runtime object is needed.

See also