Skip to content

Report more "No overload matches this call" errors on call target nodes #54447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33944,6 +33944,19 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
}

function getErrorNodeForCallNode(callLike: CallLikeExpression): Node {
if (isCallOrNewExpression(callLike)) {
return isPropertyAccessExpression(callLike.expression) ? callLike.expression.name : callLike.expression;
}
if (isTaggedTemplateExpression(callLike)) {
return isPropertyAccessExpression(callLike.tag) ? callLike.tag.name : callLike.tag;
}
if (isJsxOpeningLikeElement(callLike)) {
return callLike.tagName;
}
return callLike;
}

function isPromiseResolveArityError(node: CallLikeExpression) {
if (!isCallExpression(node) || !isIdentifier(node.expression)) return false;

Expand Down Expand Up @@ -34267,7 +34280,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
diag = { file, start, length, code: chain.code, category: chain.category, messageText: chain, relatedInformation: related };
}
else {
diag = createDiagnosticForNodeFromMessageChain(getSourceFileOfNode(node), node, chain, related);
diag = createDiagnosticForNodeFromMessageChain(getSourceFileOfNode(node), getErrorNodeForCallNode(node), chain, related);
}
addImplementationSuccessElaboration(candidatesForArgumentError[0], diag);
diagnostics.add(diag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ file.tsx(27,64): error TS2769: No overload matches this call.
Overload 2 of 2, '(linkProps: LinkProps): Element', gave the following error.
Type '{ extra: true; onClick: (k: "left" | "right") => void; }' is not assignable to type 'IntrinsicAttributes & LinkProps'.
Property 'extra' does not exist on type 'IntrinsicAttributes & LinkProps'.
file.tsx(28,12): error TS2769: No overload matches this call.
file.tsx(28,13): error TS2769: No overload matches this call.
Overload 1 of 2, '(buttonProps: ButtonProps): Element', gave the following error.
Type '{ onClick: (k: "left" | "right") => void; extra: true; }' is not assignable to type 'IntrinsicAttributes & ButtonProps'.
Property 'extra' does not exist on type 'IntrinsicAttributes & ButtonProps'.
Expand All @@ -19,7 +19,7 @@ file.tsx(29,43): error TS2769: No overload matches this call.
Overload 2 of 2, '(linkProps: LinkProps): Element', gave the following error.
Type '{ extra: true; goTo: "home"; }' is not assignable to type 'IntrinsicAttributes & LinkProps'.
Property 'extra' does not exist on type 'IntrinsicAttributes & LinkProps'.
file.tsx(30,12): error TS2769: No overload matches this call.
file.tsx(30,13): error TS2769: No overload matches this call.
Overload 1 of 2, '(buttonProps: ButtonProps): Element', gave the following error.
Type '{ goTo: string; extra: true; }' is not assignable to type 'IntrinsicAttributes & ButtonProps'.
Property 'goTo' does not exist on type 'IntrinsicAttributes & ButtonProps'.
Expand Down Expand Up @@ -69,7 +69,7 @@ file.tsx(36,44): error TS2322: Type '{ extra: true; goTo: "home"; }' is not assi
!!! error TS2769: Type '{ extra: true; onClick: (k: "left" | "right") => void; }' is not assignable to type 'IntrinsicAttributes & LinkProps'.
!!! error TS2769: Property 'extra' does not exist on type 'IntrinsicAttributes & LinkProps'.
const b2 = <MainButton onClick={(k)=>{console.log(k)}} extra />; // k has type "left" | "right"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 1 of 2, '(buttonProps: ButtonProps): Element', gave the following error.
!!! error TS2769: Type '{ onClick: (k: "left" | "right") => void; extra: true; }' is not assignable to type 'IntrinsicAttributes & ButtonProps'.
Expand All @@ -87,7 +87,7 @@ file.tsx(36,44): error TS2322: Type '{ extra: true; goTo: "home"; }' is not assi
!!! error TS2769: Type '{ extra: true; goTo: "home"; }' is not assignable to type 'IntrinsicAttributes & LinkProps'.
!!! error TS2769: Property 'extra' does not exist on type 'IntrinsicAttributes & LinkProps'.
const b4 = <MainButton goTo="home" extra />; // goTo has type "home" | "contact"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 1 of 2, '(buttonProps: ButtonProps): Element', gave the following error.
!!! error TS2769: Type '{ goTo: string; extra: true; }' is not assignable to type 'IntrinsicAttributes & ButtonProps'.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dissallowSymbolAsWeakType.ts(3,12): error TS2769: No overload matches this call.
dissallowSymbolAsWeakType.ts(3,16): error TS2769: No overload matches this call.
Overload 1 of 2, '(iterable: Iterable<object>): WeakSet<object>', gave the following error.
Argument of type 'symbol[]' is not assignable to parameter of type 'Iterable<object>'.
The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types.
Expand All @@ -11,7 +11,7 @@ dissallowSymbolAsWeakType.ts(3,12): error TS2769: No overload matches this call.
dissallowSymbolAsWeakType.ts(4,8): error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'.
dissallowSymbolAsWeakType.ts(5,8): error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'.
dissallowSymbolAsWeakType.ts(6,11): error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'.
dissallowSymbolAsWeakType.ts(8,12): error TS2769: No overload matches this call.
dissallowSymbolAsWeakType.ts(8,16): error TS2769: No overload matches this call.
Overload 1 of 2, '(iterable: Iterable<readonly [object, boolean]>): WeakMap<object, boolean>', gave the following error.
Argument of type '[symbol, false][]' is not assignable to parameter of type 'Iterable<readonly [object, boolean]>'.
The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types.
Expand All @@ -36,7 +36,7 @@ dissallowSymbolAsWeakType.ts(19,14): error TS2345: Argument of type 'symbol' is
const s: symbol = Symbol('s');

const ws = new WeakSet([s]);
~~~~~~~~~~~~~~~~
~~~~~~~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 1 of 2, '(iterable: Iterable<object>): WeakSet<object>', gave the following error.
!!! error TS2769: Argument of type 'symbol[]' is not assignable to parameter of type 'Iterable<object>'.
Expand All @@ -58,7 +58,7 @@ dissallowSymbolAsWeakType.ts(19,14): error TS2345: Argument of type 'symbol' is
!!! error TS2345: Argument of type 'symbol' is not assignable to parameter of type 'object'.

const wm = new WeakMap([[s, false]]);
~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 1 of 2, '(iterable: Iterable<readonly [object, boolean]>): WeakMap<object, boolean>', gave the following error.
!!! error TS2769: Argument of type '[symbol, false][]' is not assignable to parameter of type 'Iterable<readonly [object, boolean]>'.
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/for-of39.errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
for-of39.ts(1,11): error TS2769: No overload matches this call.
for-of39.ts(1,15): error TS2769: No overload matches this call.
Overload 1 of 4, '(iterable?: Iterable<readonly [string, boolean]>): Map<string, boolean>', gave the following error.
Argument of type '([string, number] | [string, true])[]' is not assignable to parameter of type 'Iterable<readonly [string, boolean]>'.
The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types.
Expand All @@ -15,7 +15,7 @@ for-of39.ts(1,11): error TS2769: No overload matches this call.

==== for-of39.ts (1 errors) ====
var map = new Map([["", true], ["", 0]]);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 1 of 4, '(iterable?: Iterable<readonly [string, boolean]>): Map<string, boolean>', gave the following error.
!!! error TS2769: Argument of type '([string, number] | [string, true])[]' is not assignable to parameter of type 'Iterable<readonly [string, boolean]>'.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
inheritedConstructorWithRestParams2.ts(32,13): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
inheritedConstructorWithRestParams2.ts(33,1): error TS2769: No overload matches this call.
inheritedConstructorWithRestParams2.ts(33,5): error TS2769: No overload matches this call.
Overload 1 of 3, '(x: string, ...y: number[]): Derived', gave the following error.
Argument of type 'string' is not assignable to parameter of type 'number'.
Overload 2 of 3, '(x1: string, x2: string, ...y: number[]): Derived', gave the following error.
Argument of type 'number' is not assignable to parameter of type 'string'.
inheritedConstructorWithRestParams2.ts(34,1): error TS2769: No overload matches this call.
inheritedConstructorWithRestParams2.ts(34,5): error TS2769: No overload matches this call.
Overload 1 of 3, '(x: string, ...y: number[]): Derived', gave the following error.
Argument of type 'string' is not assignable to parameter of type 'number'.
Overload 2 of 3, '(x1: string, x2: string, ...y: number[]): Derived', gave the following error.
Expand Down Expand Up @@ -47,14 +47,14 @@ inheritedConstructorWithRestParams2.ts(34,1): error TS2769: No overload matches
~
!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
new Derived("", 3, "", 3);
~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 1 of 3, '(x: string, ...y: number[]): Derived', gave the following error.
!!! error TS2769: Argument of type 'string' is not assignable to parameter of type 'number'.
!!! error TS2769: Overload 2 of 3, '(x1: string, x2: string, ...y: number[]): Derived', gave the following error.
!!! error TS2769: Argument of type 'number' is not assignable to parameter of type 'string'.
new Derived("", 3, "", "");
~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 1 of 3, '(x: string, ...y: number[]): Derived', gave the following error.
!!! error TS2769: Argument of type 'string' is not assignable to parameter of type 'number'.
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/iterableArrayPattern28.errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
iterableArrayPattern28.ts(2,24): error TS2769: No overload matches this call.
iterableArrayPattern28.ts(2,28): error TS2769: No overload matches this call.
Overload 1 of 4, '(iterable?: Iterable<readonly [string, number]>): Map<string, number>', gave the following error.
Argument of type '([string, number] | [string, boolean])[]' is not assignable to parameter of type 'Iterable<readonly [string, number]>'.
The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types.
Expand All @@ -16,7 +16,7 @@ iterableArrayPattern28.ts(2,24): error TS2769: No overload matches this call.
==== iterableArrayPattern28.ts (1 errors) ====
function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]: [string, number][]) { }
takeFirstTwoEntries(...new Map([["", 0], ["hello", true]]));
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 1 of 4, '(iterable?: Iterable<readonly [string, number]>): Map<string, number>', gave the following error.
!!! error TS2769: Argument of type '([string, number] | [string, boolean])[]' is not assignable to parameter of type 'Iterable<readonly [string, number]>'.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
index.tsx(11,5): error TS2769: No overload matches this call.
index.tsx(11,6): error TS2769: No overload matches this call.
Overload 2 of 2, '(props: PropsType, context: any): Foo', gave the following error.
Type 'unknown' is not assignable to type 'string | boolean'.
Overload 2 of 2, '(props: PropsType, context: any): Foo', gave the following error.
Expand All @@ -17,7 +17,7 @@ index.tsx(11,5): error TS2769: No overload matches this call.
declare class Foo extends React.Component<PropsType, {}> {}
const b = (
<Foo>
~~~~~
~~~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 2 of 2, '(props: PropsType, context: any): Foo', gave the following error.
!!! error TS2769: Type 'unknown' is not assignable to type 'string | boolean'.
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/jsxChildrenWrongType.errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
other.tsx(10,5): error TS2769: No overload matches this call.
other.tsx(10,6): error TS2769: No overload matches this call.
Overload 2 of 2, '(props: PropsType, context: any): Foo', gave the following error.
Type 'unknown' is not assignable to type 'string | boolean'.
Overload 2 of 2, '(props: PropsType, context: any): Foo', gave the following error.
Expand All @@ -16,7 +16,7 @@ other.tsx(10,5): error TS2769: No overload matches this call.
declare class Foo extends React.Component<PropsType, {}> {}
const b = (
<Foo>
~~~~~
~~~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 2 of 2, '(props: PropsType, context: any): Foo', gave the following error.
!!! error TS2769: Type 'unknown' is not assignable to type 'string | boolean'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ orderMattersForSignatureGroupIdentity.ts(24,20): error TS2339: Property 'toLower
var v: B;

v({ s: "", n: 0 }).toLowerCase();
~~~~~~~~~~~~~~~~~~
~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 1 of 2, '(x: { s: string; }): string', gave the following error.
!!! error TS2769: Object literal may only specify known properties, and 'n' does not exist in type '{ s: string; }'.
Expand All @@ -49,7 +49,7 @@ orderMattersForSignatureGroupIdentity.ts(24,20): error TS2339: Property 'toLower
!!! related TS6203 orderMattersForSignatureGroupIdentity.ts:21:5: 'w' was also declared here.

w({ s: "", n: 0 }).toLowerCase();
~~~~~~~~~~~~~~~~~~
~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 1 of 2, '(x: { s: string; }): string', gave the following error.
!!! error TS2769: Object literal may only specify known properties, and 'n' does not exist in type '{ s: string; }'.
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/overload1.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ overload1.ts(29,1): error TS2322: Type 'number' is not assignable to type 'strin
overload1.ts(31,11): error TS2554: Expected 1-2 arguments, but got 3.
overload1.ts(32,5): error TS2554: Expected 1-2 arguments, but got 0.
overload1.ts(33,1): error TS2322: Type 'C' is not assignable to type 'string'.
overload1.ts(34,3): error TS2769: No overload matches this call.
overload1.ts(34,5): error TS2769: No overload matches this call.
Overload 1 of 2, '(s1: string, s2: number): string', gave the following error.
Argument of type 'number' is not assignable to parameter of type 'string'.
Overload 2 of 2, '(s1: number, s2: string): number', gave the following error.
Expand Down Expand Up @@ -56,7 +56,7 @@ overload1.ts(34,3): error TS2769: No overload matches this call.
~
!!! error TS2322: Type 'C' is not assignable to type 'string'.
z=x.h(2,2); // no match
~~~~~~~~
~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 1 of 2, '(s1: string, s2: number): string', gave the following error.
!!! error TS2769: Argument of type 'number' is not assignable to parameter of type 'string'.
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/overloadTag1.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ overloadTag1.js(43,1): error TS2769: No overload matches this call.
}
var o1 = overloaded(1,2)
var o2 = overloaded("zero", "one")
~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 1 of 2, '(a: number, b: number): number', gave the following error.
!!! error TS2769: Argument of type 'string' is not assignable to parameter of type 'number'.
Expand All @@ -64,7 +64,7 @@ overloadTag1.js(43,1): error TS2769: No overload matches this call.
}
uncheckedInternally(1,2)
uncheckedInternally("zero", "one")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 1 of 2, '(a: number, b: number): number', gave the following error.
!!! error TS2769: Argument of type 'string' is not assignable to parameter of type 'number'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ overloadresolutionWithConstraintCheckingDeferred.ts(19,14): error TS2344: Type '
declare function foo(arg: (x: B) => any): number;

var result: number = foo(x => new G(x)); // x has type D, new G(x) fails, so first overload is picked.
~~~~~~~~~~~~~~~~~~
~~~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 1 of 3, '(arg: (x: D) => number): string', gave the following error.
!!! error TS2769: Type 'G<A>' is not assignable to type 'number'.
Expand All @@ -74,7 +74,7 @@ overloadresolutionWithConstraintCheckingDeferred.ts(19,14): error TS2344: Type '
!!! related TS2728 overloadresolutionWithConstraintCheckingDeferred.ts:1:15: 'x' is declared here.

var result2: number = foo(x => new G<typeof x>(x)); // x has type D, new G(x) fails, so first overload is picked.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 1 of 3, '(arg: (x: D) => number): string', gave the following error.
!!! error TS2769: Type 'G<D>' is not assignable to type 'number'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ overloadsWithProvisionalErrors.ts(8,17): error TS2304: Cannot find name 'blah'.
};

func(s => ({})); // Error for no applicable overload (object type is missing a and b)
~~~~~~~~~~~~~~~
~~~~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 1 of 2, '(s: string): number', gave the following error.
!!! error TS2769: Argument of type '(s: string) => {}' is not assignable to parameter of type 'string'.
Expand All @@ -30,7 +30,7 @@ overloadsWithProvisionalErrors.ts(8,17): error TS2304: Cannot find name 'blah'.
~~~~
!!! error TS2304: Cannot find name 'blah'.
func(s => ({ a: blah })); // Two errors here, one for blah not being defined, and one for the overload since it would not be applicable anyway
~~~~~~~~~~~~~~~~~~~~~~~~
~~~~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 1 of 2, '(s: string): number', gave the following error.
!!! error TS2769: Argument of type '(s: string) => { a: any; }' is not assignable to parameter of type 'string'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ specializedSignatureAsCallbackParameter1.ts(8,1): error TS2769: No overload matc
}
// both are errors
x3(1, (x: string) => 1);
~~~~~~~~~~~~~~~~~~~~~~~
~~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 1 of 2, '(a: number, cb: (x: number) => number): any', gave the following error.
!!! error TS2769: Argument of type '(x: string) => number' is not assignable to parameter of type '(x: number) => number'.
Expand All @@ -31,7 +31,7 @@ specializedSignatureAsCallbackParameter1.ts(8,1): error TS2769: No overload matc
!!! error TS2769: Overload 2 of 2, '(a: string, cb: (x: number) => number): any', gave the following error.
!!! error TS2769: Argument of type 'number' is not assignable to parameter of type 'string'.
x3(1, (x: 'hm') => 1);
~~~~~~~~~~~~~~~~~~~~~
~~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 1 of 2, '(a: number, cb: (x: number) => number): any', gave the following error.
!!! error TS2769: Argument of type '(x: 'hm') => number' is not assignable to parameter of type '(x: number) => number'.
Expand Down
Loading