Upgraded and Enhanced Enums
Learn about the upgraded and enhanced enums of TypeScript 5.0.
We'll cover the following
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 enums as union enums, making them safer and easier to work with.
Until TypeScript 5.0, an enum was just a set of numeric constraints. Let’s say we had an enum that tracked the state of an HTTP request:
Get hands-on with 1400+ tech skills courses.