Aller au contenu

noEnum

Ce contenu n’est pas encore disponible dans votre langue.

Diagnostic Category: lint/nursery/noEnum

Since: v1.9.0

Disallow TypeScript enum.

TypeScript enums are not a type-level extension to JavaScript like type annotations or definitions. Users may wish to disable non-type-level extensions to use bundlers or compilers that only strip types.

Const enums are not covered by this rule since noConstEnum already handles them. Enums within the ambient context, including declaration files, are ignores as well.

enum Foo {
BAR = 'bar',
BAZ = 'baz',
}
code-block.ts:1:1 lint/nursery/noEnum ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Don’t use enum

> 1 │ enum Foo {
^^^^^^^^^^
> 2 │ BAR = ‘bar’,
> 3 │ BAZ = ‘baz’,
> 4 │ }
^
5 │

TypeScript enums are not a type-level extension to JavaScript like type annotations or definitions. Users may wish to disable non-type-level extensions to use bundlers or compilers that only strip types.

Use JavaScript objects or TypeScript unions instead.

const Foo = {
BAR: 'bar',
BAZ: 'baz',
} as const
type Foo = 'bar' | 'baz'
const enum Foo {
BAR = 'bar',
BAZ = 'baz',
}