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.