enumInitializers
Reports enum members without explicit initial values.
✅ This rule is included in the ts logical presets.
TypeScript enums assign sequentially increasing numbers to members that don’t have explicit values. This behavior can cause unintended value changes if enum members are reordered, added, or removed. Explicitly initializing each enum member prevents these issues and makes the code’s intent clearer.
Examples
Section titled “Examples”enum Status { Pending, Active, Completed,}enum Direction { Up, Down,}enum Status { Pending = 0, Active = 1, Completed = 2,}enum Direction { Up = "Up", Down = "Down",}Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If the numeric values of enum members are not important to your project, you may not need this rule. This can be the case when enums are only used for type safety and the actual runtime values are never inspected or stored externally.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.