Skip to content

typescript/prefer-literal-enum-member Restriction ​

What it does ​

Explicit enum value must only be a literal value (string, number, boolean, etc).

Why is this bad? ​

TypeScript allows the value of an enum member to be many different kinds of valid JavaScript expressions. However, because enums create their own scope whereby each enum member becomes a variable in that scope, developers are often surprised at the resultant values.

Example ​

ts
const imOutside = 2;
const b = 2;
enum Foo {
  outer = imOutside,
  a = 1,
  b = a,
  c = b,
}

How to use ​

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny typescript/prefer-literal-enum-member
json
{
  "rules": {
    "typescript/prefer-literal-enum-member": "error"
  }
}

References ​

Released under the MIT License.