Enum
In one line
An enum is a TypeScript feature that defines a set of named constants, either numeric or string-based, making code more readable and self-documenting.
In simple words
An enum gives friendly names to a set of values. For example, enum Direction { Up, Down, Left, Right } lets you use Direction.Up instead of magic numbers like 0.
Numeric enums auto-assign values starting at 0. String enums require explicit string values. Unlike most TypeScript features, enums are NOT erased — they compile to real JavaScript objects that exist at runtime.
Enums are useful for representing a fixed set of options: directions, statuses, colors, error codes. However, string literal unions (type Direction = "up" | "down") are often preferred for being simpler and fully erased.
Example
enum Status { Active, Inactive, Pending }
console.log(Status.Active); // 0
enum Color { Red = "RED", Green = "GREEN" }
console.log(Color.Red); // "RED"Numeric enums auto-increment from 0. String enums need explicit values.
Related terms
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.