Search⌘ K
AI Features

Upgraded and Enhanced Enums

Discover how TypeScript 5.0 upgrades enums by treating them as union types, improving type safety and preventing invalid values. Learn to apply these changes effectively to write safer and more maintainable TypeScript code.

Introduction to enums

Enums—a handy (if somewhat underappreciated) way of defining a set of named constants—have greatly boosted TypeScript 5.0.

In the past, we could have accidentally passed an incorrect number to a function expecting an enum and gotten away with it. TypeScript 5.0 is a lot stricter. It will throw an error if there’s a mismatch. It now treats all ...