What are Enums in TypeScript?
Enums in TypeScript are not a type-level extension of JavaScript. Enums are a set of named constants.
Enums are immutable. It also provides a few things:
- a closed set of well known values
- a respective set of literal-like types for each member
- by a single named type which encompasses all values
Enums make it easier to document intent or create a set of distinct cases. TypeScript provides both numeric and string-based enums.
Example of Enum
enum subscriberState { Inactive, Active, Expired, Unknown } const activeState = subscriberState.Active; console.log(activeState);