Skip to content

noConstEnum

  • Rule available since: v1.0.0
  • Diagnostic Category: lint/suspicious/noConstEnum
  • This rule is recommended, which means is enabled by default.
  • This rule has a safe fix.
  • The default severity of this rule is error.

Disallow TypeScript const enum

Const enums are enums that should be inlined at use sites. Const enums are not supported by bundlers and are incompatible with the isolatedModules mode. Their use can lead to import nonexistent values (because const enums are erased).

Thus, library authors and bundler users should not use const enums.

const enum Status {
Open,
Close,
}
code-block.ts:1:1 lint/suspicious/noConstEnum  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

The enum declaration should not be const

> 1 │ const enum Status {
^^^^^^^^^^^^^^^^^^^
> 2 │ Open,
> 3 │ Close,
> 4 │ }
^
5 │

Const enums are not supported by bundlers and are incompatible with the ‘isolatedModules’ mode. Their use can lead to import inexistent values.

See TypeScript Docs for more details.

Safe fix: Turn the const enum into a regular enum.

1 │ const·enum·Status·{
------
enum Status {
Open,
Close,
}
biome.json
{
"linter": {
"rules": {
"suspicious": {
"noConstEnum": "error"
}
}
}
}