Enums
Part of the TypeScript course
Some values come from a short, fixed list. An order is pending, shipped or delivered. A log line is debug, info, warn or error. A direction is up, down, left or right. Writing those as plain strings works right up until someone types "shiped", and then a comparison silently fails and the order sits in a state nothing handles.
An enum, short for enumeration, is a named set of the allowed values. You define the list once, refer to its members by name everywhere else, and a typo becomes a compile error instead of a mystery. ...
Want to learn TypeScript Enums in a real environment?
Click below, get a fresh Linux box with TypeScript ready to go, and work through Enums hands-on with an AI tutor that knows your code.
Start this lessonEnumsWhat you'll learn
- Numeric enums
- String enums
- Const enums
- Enums vs string literal unions
- Reverse mapping caveats
Read this lesson in your language
All lessons in this course
18 lessons- 1Hello, TypeScript20 min
- 2Type Basics25 min
- 3Arrays and Tuples25 min
- 4Object Types and Interfaces25 min
- 5Functions25 min
- 6Union and Literal Types25 min
- 7Type Narrowing30 min
- 8Type Aliases vs Interfaces20 min
- 9Optional, Readonly, and Nullable25 min
- 10Enums20 min
- 11Generics30 min
- 12Classes25 min
- 13Inheritance and Abstract Classes25 min
- 14Modules25 min
- 15Utility Types30 min
- 16Mapped and Conditional Types30 min
- 17Declaration Files and Libraries25 min
- 18tsconfig and the Compiler30 min
