Argument arity error should only consider signatures with correct type

argument arity.

Fixes #26835.
This commit is contained in:
Matt McCutchen
2018-09-01 19:48:47 -04:00
parent 45101491c0
commit f2d26fd0bb
6 changed files with 68 additions and 8 deletions

View File

@@ -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);