diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index da1af15dfa4..e52f89e9a06 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -19174,14 +19174,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); diff --git a/tests/baselines/reference/functionCall18.errors.txt b/tests/baselines/reference/functionCall18.errors.txt new file mode 100644 index 00000000000..99d7415425c --- /dev/null +++ b/tests/baselines/reference/functionCall18.errors.txt @@ -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(a: T, b: T); + declare function foo(a: {}); + foo("hello"); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2554: Expected 2 arguments, but got 1. + \ No newline at end of file diff --git a/tests/baselines/reference/functionCall18.js b/tests/baselines/reference/functionCall18.js new file mode 100644 index 00000000000..6e059205c62 --- /dev/null +++ b/tests/baselines/reference/functionCall18.js @@ -0,0 +1,9 @@ +//// [functionCall18.ts] +// Repro from #26835 +declare function foo(a: T, b: T); +declare function foo(a: {}); +foo("hello"); + + +//// [functionCall18.js] +foo("hello"); diff --git a/tests/baselines/reference/functionCall18.symbols b/tests/baselines/reference/functionCall18.symbols new file mode 100644 index 00000000000..ebf635d91e9 --- /dev/null +++ b/tests/baselines/reference/functionCall18.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/functionCall18.ts === +// Repro from #26835 +declare function foo(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("hello"); +>foo : Symbol(foo, Decl(functionCall18.ts, 0, 0), Decl(functionCall18.ts, 1, 36)) + diff --git a/tests/baselines/reference/functionCall18.types b/tests/baselines/reference/functionCall18.types new file mode 100644 index 00000000000..90fa33f0617 --- /dev/null +++ b/tests/baselines/reference/functionCall18.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/functionCall18.ts === +// Repro from #26835 +declare function foo(a: T, b: T); +>foo : { (a: T, b: T): any; (a: {}): any; } +>a : T +>b : T + +declare function foo(a: {}); +>foo : { (a: T, b: T): any; (a: {}): any; } +>a : {} + +foo("hello"); +>foo("hello") : any +>foo : { (a: T, b: T): any; (a: {}): any; } +>"hello" : "hello" + diff --git a/tests/cases/compiler/functionCall18.ts b/tests/cases/compiler/functionCall18.ts new file mode 100644 index 00000000000..848580db729 --- /dev/null +++ b/tests/cases/compiler/functionCall18.ts @@ -0,0 +1,4 @@ +// Repro from #26835 +declare function foo(a: T, b: T); +declare function foo(a: {}); +foo("hello");