• Error
  • Reported by the type checker

TS2393

Duplicate function implementation.

Two functions or methods with the same name both have a body in the same scope. Remove or rename one of them.

What it means

A name can have several overload signatures but only one implementation. A second function declaration with a body in the same scope (or class) is reported on both.

Example

index.ts
export function area(r: number): number {
  return Math.PI * r * r;
}
export function area(w: number, h: number): number {
  return w * h;
}
ts-r-check -p tsconfig.json --pretty false ts-r output
index.ts(1,17): error TS2393: Duplicate function implementation.
index.ts(4,17): error TS2393: Duplicate function implementation.

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 one of the functions (circleArea, rectArea).
  • Or merge them into one implementation and describe the forms with overload signatures.