✅ This rule is included in the ts logicalStrict presets.
TypeScript allows enum members to be initialized with various expressions.
However, using computed values can lead to unexpected results because enums create their own scope where each enum member becomes a variable.
For example, in this code:
const
const imOutside:2
imOutside = 2;
enum
enum Foo
Foo {
function(enummember)Foo.a = 1
a=1,
function(enummember)Foo.b = 1
b=
function(enummember)Foo.a = 1
a,
function(enummember)Foo.c = 2
c=
const imOutside:2
imOutside,
}
Foo.b will be 1 (referencing Foo.a), but Foo.c will also be 1 because imOutside is shadowed by the auto-incremented value.
This rule requires all enum members to use literal values (strings or numbers) to prevent such confusion.
If you want to use computed expressions as enum values and understand the scoping implications, you may prefer to disable this rule.
Some projects intentionally use enums as “opaque” entities where the values are not important.