To fix the ‘ts2769: no overload matches this call.’ error with TypeScript, we should call a function with the arguments that matches one of the signatures of the function.
For instance, we write
function foo(str: "hello"): string;
function foo(str: "world"): string;
function foo(str: "hello" | "world"): string {
return str;
}
foo("hello");
to define the foo
function with multiple signatures.
It accepts the str
parameter which can be either 'hello'
or 'world'
.
And then we call foo
with 'hello'
to we avoid the error.
If we call foo
with something other than 'hello'
or 'world'
, then we get this error.