• Error
  • Reported by the binder

TS2567

Enum declarations can only merge with namespace or other enum declarations.

An enum shares its name with a class, function, interface or variable. Rename one of them; enums only merge with other enums and namespaces.

What it means

An enum can be declared more than once, and it can merge with a namespace of the same name. It can't share its name with any other kind of declaration, such as a function, class or variable, because the enum's object and the other value would collide at runtime.

Example

index.ts
enum Color { Red }
function Color() {}
export {};
ts-r-check -p tsconfig.json --pretty false ts-r output
index.ts(1,6): error TS2567: Enum declarations can only merge with namespace or other enum declarations.
index.ts(2,10): error TS2567: Enum declarations can only merge with namespace or other enum declarations.

Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01. The example uses the default tsconfig: strict, target: es2022, module: esnext, moduleResolution: bundler.

How to fix

  • Rename the enum or the other declaration.
  • If you wanted to add members or helpers to the enum, use a namespace of the same name.