typescript
function_error
ai_generated
true
TS2394: This overload signature is not compatible with its implementation signature
ID: typescript/ts-overload-signature-error
88%Fix Rate
90%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 5 | active | — | — | — |
Root Cause
The implementation signature must be compatible with all overload signatures. It must accept a superset of all parameter types.
genericWorkarounds
-
92% success Ensure the implementation signature accepts all overload parameter types
function parse(input: string): Document; function parse(input: Buffer): Document; function parse(input: string | Buffer): Document { // implementation handles both types const text = typeof input === 'string' ? input : input.toString(); return parseDocument(text); }Sources: https://www.typescriptlang.org/docs/handbook/2/functions.html#function-overloads
-
85% success Use a union type in the implementation for return types
function getValue(key: 'name'): string; function getValue(key: 'age'): number; function getValue(key: 'name' | 'age'): string | number { // implementation return type is union of all overload returns }
Dead Ends
Common approaches that don't work:
-
Make each overload signature identical to the implementation
65% fail
Defeats the purpose of overloads; overloads should provide narrower type signatures for callers
Error Chain
Preceded by:
Frequently confused with: