oxc/no-const-enum
Disallow TypeScript const enum
fixable
A const enum doesn't exist at runtime. TypeScript replaces each use with the member's value, and to do that it has to read the file that declares the enum. A tool that compiles one file at a time can't do that for an imported enum. If the enum is in a published .d.ts file, its values are copied into every package compiled against it, and they go stale when the enum changes.
--fix removes const, which makes it a regular enum.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"oxc/no-const-enum" = "error" # or "warn"Examples#
example.ts1 problem
export constUnexpected const enum enum Status {
Active,
Archived,
}example.tsNo problems
export enum Status {
Active,
Archived,
}An object with as const gives you plain values without an enum:
example.tsNo problems
export const Status = {
Active: 0,
Archived: 1,
} as const;