Skip to main content

no-const-enum

Disallow TypeScript const enum declarations.

Targeted pattern scope

This rule inspects TSEnumDeclaration nodes and reports when the declaration is marked const.

With allowLocal: true, non-exported const enum declarations are allowed.

What this rule reports

This rule reports const enum declarations. const enum relies on TypeScript-specific inlining behavior and can cause compatibility issues in mixed toolchains.

Why this rule exists

const enum depends on compile-time inlining semantics that can break in mixed toolchains and isolated transpilation flows.

❌ Incorrect

const enum Status {
Ready,
Running,
}

✅ Correct

enum Status {
Ready,
Running,
}

Behavior and migration notes

This rule reports only and does not provide an autofix.

Migration options:

  • convert const enum to regular enum, or
  • replace with as const object + union type.

Options

type Options = {
allowLocal?: boolean;
};

Default: { allowLocal: false }

allowLocal

When true, non-exported const enum declarations are allowed.

Additional examples

// config: { allowLocal: true }
const enum LocalKind {
A,
}
// ✅ allowed when not exported

export const enum PublicKind {
A,
}
// ❌ still reported

ESLint flat config example

import etcMisc from "eslint-plugin-etc-misc";

export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/no-const-enum": ["error", { allowLocal: true }],
},
},
];

When not to use it

Disable this rule if your project explicitly depends on const enum inlining and your build toolchain guarantees consistent handling.

Package documentation

Rule catalog ID: R021

Further reading

Adoption resources

  • Start at warning level in CI, then move to error after cleanup.
  • Use focused codemods/autofix batches per package or directory.