enumValueConsistency
Reports enums that contain both string and number members.
✅ This rule is included in the ts logical presets.
TypeScript enums can have members with numeric or string values. While it’s technically possible to mix both types in the same enum, doing so creates confusing iteration behavior.
When you iterate over an enum using Object.keys(), Object.values(), or Object.entries():
- String enums produce exactly the number of items matching enum members
- Numeric enums produce double the items due to reverse mappings (value-to-name mappings)
- Mixed enums produce both numbers and strings
This rule requires all enum members to consistently use either all numbers or all strings.
Examples
Section titled “Examples”enum Status { Active = 0, Inactive = "inactive",}enum Mixed { First, Second = "second",}enum Status { Active = 0, Inactive = 1,}enum Status { Active = "active", Inactive = "inactive",}enum Direction { Up, Down, Left, Right,}Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you don’t iterate over enums and don’t mind the confusion of mixed enum member values, you may disable this rule. Some codebases intentionally use mixed enums for specific use cases where the iteration behavior is well understood.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
@typescript-eslint/no-mixed-enums - Oxlint:
typescript/no-mixed-enums
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.