no-duplicate-enum-values
Disallow duplicate enum member values.
🔒
Extending "plugin:@typescript-eslint/strict"
in an ESLint configuration enables this rule.
Although TypeScript supports duplicate enum member values, people usually expect members to have unique values within the same enum. Duplicate values can lead to bugs that are hard to track down.
.eslintrc.cjs
module.exports = {
"rules": {
"@typescript-eslint/no-duplicate-enum-values": "warn"
}
};
Examples
This rule disallows defining an enum with multiple members initialized to the same value.
This rule only enforces on enum members initialized with string or number literals. Members without an initializer or initialized with an expression are not checked by this rule.
- ❌ Incorrect
- ✅ Correct
enum E {
A = 0,
B = 0,
}
enum E {
A = 'A',
B = 'A',
}
enum E {
A = 0,
B = 1,
}
enum E {
A = 'A',
B = 'B',
}
Options
This rule is not configurable.