TypeScript Reference ยท Error Codes Worth Knowing
TypeScript error TS2769: no overload matches this call
TS2769 means none of a function's overload signatures accepts your arguments. Learn how to read the nested messages, find the right overload, and fix the call.
TS2769 reads No overload matches this call. The function you called has several signatures (an overload list), and the compiler tried each one in order without finding a match. Many standard-library functions are overloaded: addEventListener, Array.prototype.reduce, Promise.all, new Date(...), fs.readFileSync, and most of the web APIs.
The hard part is the message. TypeScript reports why the last overload (sometimes also the best candidate) failed, and that may not be the overload you meant. Read the nested lines, then check the argument that does not fit, not just the first complaint.
function pick(x: string): string; function pick(x: number): number; function pick(x: string | number) { return x; } pick(true); // error TS2769
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
Syntax
How resolution works:
| Step | Rule |
|---|---|
| Order | Overloads are tried from top to bottom; the first that accepts the call wins. |
| Arity | An overload with the wrong number of parameters is skipped. |
| Contextual typing | Arrow function arguments are typed from each candidate in turn. |
| Failure | If none fits, TS2769 is reported, with the reason for the last (or closest) candidate nested below. |
| Implementation signature | The final signature with the body is not visible to callers. |
Usage notes
- Union arguments are the usual surprise.
pick(x)withx: string | numberfails because no single overload takes the union. Narrow first, or add an overload that accepts the union. - Put specific overloads before general ones. A catch-all such as
(x: unknown): unknownplaced first shadows everything after it. - The message hints at the real problem.
Argument of type 'boolean' is not assignable to parameter of type 'number'points at the last overload; check whether another overload was closer. - Callbacks. When the error is inside an arrow function, a mistake in its body can make every overload fail. Annotate the callback to see the true error.
- Library calls. Look up the overloads (hover in your editor, or open the
.d.ts) and match one of them exactly, for example choosing thePromise.alltuple form or thereadFileSyncoptions form that returns a string. - Prefer a union or generic over many overloads when a function body is the same for every case. Overloads are for different return types per input.
Related
- Function overloads, TS2345, TS2554, Union narrowing
- Lessons: Overloads, Function types