Skip to content

Commit 69f91b5

Browse files
Merge pull request #26837 from mattmccutchen/issue-26835
Argument arity error should only consider signatures with correct type argument arity.
2 parents 4717ddb + f2d26fd commit 69f91b5

File tree

6 files changed

+68
-8
lines changed

6 files changed

+68
-8
lines changed

src/compiler/checker.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19246,14 +19246,17 @@ namespace ts {
1924619246
else if (candidateForTypeArgumentError) {
1924719247
checkTypeArguments(candidateForTypeArgumentError, (node as CallExpression | TaggedTemplateExpression).typeArguments!, /*reportErrors*/ true, fallbackError);
1924819248
}
19249-
else if (typeArguments && every(signatures, sig => typeArguments!.length < getMinTypeArgumentCount(sig.typeParameters) || typeArguments!.length > length(sig.typeParameters))) {
19250-
diagnostics.add(getTypeArgumentArityError(node, signatures, typeArguments));
19251-
}
19252-
else if (!isDecorator) {
19253-
diagnostics.add(getArgumentArityError(node, signatures, args));
19254-
}
19255-
else if (fallbackError) {
19256-
diagnostics.add(createDiagnosticForNode(node, fallbackError));
19249+
else {
19250+
const signaturesWithCorrectTypeArgumentArity = filter(signatures, s => hasCorrectTypeArgumentArity(s, typeArguments));
19251+
if (signaturesWithCorrectTypeArgumentArity.length === 0) {
19252+
diagnostics.add(getTypeArgumentArityError(node, signatures, typeArguments!));
19253+
}
19254+
else if (!isDecorator) {
19255+
diagnostics.add(getArgumentArityError(node, signaturesWithCorrectTypeArgumentArity, args));
19256+
}
19257+
else if (fallbackError) {
19258+
diagnostics.add(createDiagnosticForNode(node, fallbackError));
19259+
}
1925719260
}
1925819261

1925919262
return produceDiagnostics || !args ? resolveErrorCall(node) : getCandidateForOverloadFailure(node, candidates, args, !!candidatesOutArray);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
tests/cases/compiler/functionCall18.ts(4,1): error TS2554: Expected 2 arguments, but got 1.
2+
3+
4+
==== tests/cases/compiler/functionCall18.ts (1 errors) ====
5+
// Repro from #26835
6+
declare function foo<T>(a: T, b: T);
7+
declare function foo(a: {});
8+
foo<string>("hello");
9+
~~~~~~~~~~~~~~~~~~~~
10+
!!! error TS2554: Expected 2 arguments, but got 1.
11+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//// [functionCall18.ts]
2+
// Repro from #26835
3+
declare function foo<T>(a: T, b: T);
4+
declare function foo(a: {});
5+
foo<string>("hello");
6+
7+
8+
//// [functionCall18.js]
9+
foo("hello");
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=== tests/cases/compiler/functionCall18.ts ===
2+
// Repro from #26835
3+
declare function foo<T>(a: T, b: T);
4+
>foo : Symbol(foo, Decl(functionCall18.ts, 0, 0), Decl(functionCall18.ts, 1, 36))
5+
>T : Symbol(T, Decl(functionCall18.ts, 1, 21))
6+
>a : Symbol(a, Decl(functionCall18.ts, 1, 24))
7+
>T : Symbol(T, Decl(functionCall18.ts, 1, 21))
8+
>b : Symbol(b, Decl(functionCall18.ts, 1, 29))
9+
>T : Symbol(T, Decl(functionCall18.ts, 1, 21))
10+
11+
declare function foo(a: {});
12+
>foo : Symbol(foo, Decl(functionCall18.ts, 0, 0), Decl(functionCall18.ts, 1, 36))
13+
>a : Symbol(a, Decl(functionCall18.ts, 2, 21))
14+
15+
foo<string>("hello");
16+
>foo : Symbol(foo, Decl(functionCall18.ts, 0, 0), Decl(functionCall18.ts, 1, 36))
17+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=== tests/cases/compiler/functionCall18.ts ===
2+
// Repro from #26835
3+
declare function foo<T>(a: T, b: T);
4+
>foo : { <T>(a: T, b: T): any; (a: {}): any; }
5+
>a : T
6+
>b : T
7+
8+
declare function foo(a: {});
9+
>foo : { <T>(a: T, b: T): any; (a: {}): any; }
10+
>a : {}
11+
12+
foo<string>("hello");
13+
>foo<string>("hello") : any
14+
>foo : { <T>(a: T, b: T): any; (a: {}): any; }
15+
>"hello" : "hello"
16+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Repro from #26835
2+
declare function foo<T>(a: T, b: T);
3+
declare function foo(a: {});
4+
foo<string>("hello");

0 commit comments

Comments
 (0)