Skip to content

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.

enum Status {
Active = 0,
Inactive = "inactive",
}
enum Mixed {
First,
Second = "second",
}

This rule is not configurable.

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.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.