Skip to content

TypeScript · maintainability

no-enum

eslint:no-enum

Disallow TypeScript `enum`; use string-literal unions or `as const` objects instead.

Default
error
Fix
none
Languages
typescript

Why

TypeScript enums emit runtime objects and numeric enums accept values outside their declared members, adding behavior where a type-only model is sufficient.

Fix

Replace the enum with a string-literal union or an `as const` object and derive its value type from that object.

Before / after

Executed by this rule’s unit tests.

Before

A numeric enum emits a mutable runtime object

src/status.ts · focus
enum Status { Active, Inactive }

After

A string-literal union has no emitted runtime enum

src/status.ts · focus
type Status = "active" | "inactive";

Message IDs

noEnum

Options

{
  "additionalProperties": false,
  "properties": {
    "ignoreFiles": {
      "description": "Additional generated-file globs to ignore; shared generated paths and header markers are always ignored.",
      "items": {
        "type": "string"
      },
      "type": "array"
    }
  },
  "type": "object"
}