useLiteralEnumMembers
Ce contenu n’est pas encore disponible dans votre langue.
Diagnostic Category: lint/style/useLiteralEnumMembers
Since: v1.0.0
Sources:
Require all enum members to be literal values.
Usually, an enum member is initialized with a literal number or a literal string. However, TypeScript allows the value of an enum member to be many different kinds of expressions. Using a computed enum member is often error-prone and confusing. This rule requires the initialization of enum members with constant expressions. It allows numeric and bitwise expressions for supporting enum flags. It also allows referencing previous enum members.
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-block.ts:4:9 lint/style/useLiteralEnumMembers ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The enum member should be initialized with a literal value such as a number or a string.
2 │ enum Computed {
3 │ A,
> 4 │ B = x,
│ ^
5 │ }
6 │