- Error
- Reported by the type checker
TS2392
Multiple constructor implementations are not allowed.
A class has more than one constructor with a body. Keep one implementation and turn the other forms into overload signatures.
What it means
JavaScript classes have a single constructor. TypeScript lets you describe several ways to call it with overload signatures, but only one constructor may have a body.
Example
export class Range {
constructor(start: number) {}
constructor(start: number, end: number) {}
}
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(2,3): error TS2392: Multiple constructor implementations are not allowed.
index.ts(3,3): error TS2392: Multiple constructor implementations are not allowed.
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
- Keep one constructor with a body; give it optional parameters or a union so it covers every case.
- Write the other forms as overload signatures (no body) before it.
- Or add static factory methods such as
Range.from(start, end).