quick-lint-js

Find bugs in JavaScript programs.

E0251: enum value must be a compile-time constant

In TypeScript, normal enums can contain computed values. However, enums declared with const enum, declare enum, or declare const enum must only contain compile-time constants. It is an error to write a non-constant value in an enum which requires constant values:

declare enum LogLevel {
  ERROR = 1,
  INFO = 2,
  DEBUG = 3,
  DEFAULT = getDefaultLogLevel(),
}

To fix this error, convert the enum member into a variable:

declare enum LogLevel {
  ERROR = 1,
  INFO = 2,
  DEBUG = 3,
}
const DEFAULT_LOG_LEVEL: LogLevel
  = getDefaultLogLevel();

Alternatively, use a normal enum:

enum LogLevel {
  ERROR = 1,
  INFO = 2,
  DEBUG = 3,
  DEFAULT = getDefaultLogLevel(),
}

Documentation for other errors