Merge pull request #26837 from mattmccutchen/issue-26835

Argument arity error should only consider signatures with correct type argument arity.
This commit is contained in:
Ryan Cavanaugh 2018-09-05 12:22:48 -07:00 committed by GitHub
commit 69f91b5ed8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 68 additions and 8 deletions

View file

@ -19246,14 +19246,17 @@ namespace ts {
else if (candidateForTypeArgumentError) {
checkTypeArguments(candidateForTypeArgumentError, (node as CallExpression | TaggedTemplateExpression).typeArguments!, /*reportErrors*/ true, fallbackError);
}
else if (typeArguments && every(signatures, sig => typeArguments!.length < getMinTypeArgumentCount(sig.typeParameters) || typeArguments!.length > length(sig.typeParameters))) {
diagnostics.add(getTypeArgumentArityError(node, signatures, typeArguments));
}
else if (!isDecorator) {
diagnostics.add(getArgumentArityError(node, signatures, args));
}
else if (fallbackError) {
diagnostics.add(createDiagnosticForNode(node, fallbackError));
else {
const signaturesWithCorrectTypeArgumentArity = filter(signatures, s => hasCorrectTypeArgumentArity(s, typeArguments));
if (signaturesWithCorrectTypeArgumentArity.length === 0) {
diagnostics.add(getTypeArgumentArityError(node, signatures, typeArguments!));
}
else if (!isDecorator) {
diagnostics.add(getArgumentArityError(node, signaturesWithCorrectTypeArgumentArity, args));
}
else if (fallbackError) {
diagnostics.add(createDiagnosticForNode(node, fallbackError));
}
}
return produceDiagnostics || !args ? resolveErrorCall(node) : getCandidateForOverloadFailure(node, candidates, args, !!candidatesOutArray);

View file

@ -0,0 +1,11 @@
tests/cases/compiler/functionCall18.ts(4,1): error TS2554: Expected 2 arguments, but got 1.
==== tests/cases/compiler/functionCall18.ts (1 errors) ====
// Repro from #26835
declare function foo<T>(a: T, b: T);
declare function foo(a: {});
foo<string>("hello");
~~~~~~~~~~~~~~~~~~~~
!!! error TS2554: Expected 2 arguments, but got 1.

View file

@ -0,0 +1,9 @@
//// [functionCall18.ts]
// Repro from #26835
declare function foo<T>(a: T, b: T);
declare function foo(a: {});
foo<string>("hello");
//// [functionCall18.js]
foo("hello");

View file

@ -0,0 +1,17 @@
=== tests/cases/compiler/functionCall18.ts ===
// Repro from #26835
declare function foo<T>(a: T, b: T);
>foo : Symbol(foo, Decl(functionCall18.ts, 0, 0), Decl(functionCall18.ts, 1, 36))
>T : Symbol(T, Decl(functionCall18.ts, 1, 21))
>a : Symbol(a, Decl(functionCall18.ts, 1, 24))
>T : Symbol(T, Decl(functionCall18.ts, 1, 21))
>b : Symbol(b, Decl(functionCall18.ts, 1, 29))
>T : Symbol(T, Decl(functionCall18.ts, 1, 21))
declare function foo(a: {});
>foo : Symbol(foo, Decl(functionCall18.ts, 0, 0), Decl(functionCall18.ts, 1, 36))
>a : Symbol(a, Decl(functionCall18.ts, 2, 21))
foo<string>("hello");
>foo : Symbol(foo, Decl(functionCall18.ts, 0, 0), Decl(functionCall18.ts, 1, 36))

View file

@ -0,0 +1,16 @@
=== tests/cases/compiler/functionCall18.ts ===
// Repro from #26835
declare function foo<T>(a: T, b: T);
>foo : { <T>(a: T, b: T): any; (a: {}): any; }
>a : T
>b : T
declare function foo(a: {});
>foo : { <T>(a: T, b: T): any; (a: {}): any; }
>a : {}
foo<string>("hello");
>foo<string>("hello") : any
>foo : { <T>(a: T, b: T): any; (a: {}): any; }
>"hello" : "hello"

View file

@ -0,0 +1,4 @@
// Repro from #26835
declare function foo<T>(a: T, b: T);
declare function foo(a: {});
foo<string>("hello");