diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 73147bb99bb..62c89346202 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15208,7 +15208,7 @@ namespace ts { } } - function resolveCall(node: CallLikeExpression, signatures: Signature[], candidatesOutArray: Signature[], headMessage?: DiagnosticMessage): Signature { + function resolveCall(node: CallLikeExpression, signatures: Signature[], candidatesOutArray: Signature[], fallbackError?: DiagnosticMessage): Signature { const isTaggedTemplate = node.kind === SyntaxKind.TaggedTemplateExpression; const isDecorator = node.kind === SyntaxKind.Decorator; const isJsxOpeningOrSelfClosingElement = isJsxOpeningLikeElement(node); @@ -15243,7 +15243,7 @@ namespace ts { // reorderCandidates fills up the candidates array directly reorderCandidates(signatures, candidates); if (!candidates.length) { - reportError(Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); + diagnostics.add(createDiagnosticForNode(node, Diagnostics.Call_target_does_not_contain_any_signatures)); return resolveErrorCall(node); } @@ -15351,7 +15351,7 @@ namespace ts { else if (candidateForTypeArgumentError) { if (!isTaggedTemplate && !isDecorator && typeArguments) { const typeArguments = (node).typeArguments; - checkTypeArguments(candidateForTypeArgumentError, typeArguments, map(typeArguments, getTypeFromTypeNode), /*reportErrors*/ true, headMessage); + checkTypeArguments(candidateForTypeArgumentError, typeArguments, map(typeArguments, getTypeFromTypeNode), /*reportErrors*/ true, fallbackError); } else { Debug.assert(resultOfFailedInference.failedTypeParameterIndex >= 0); @@ -15362,8 +15362,8 @@ namespace ts { Diagnostics.The_type_argument_for_type_parameter_0_cannot_be_inferred_from_the_usage_Consider_specifying_the_type_arguments_explicitly, typeToString(failedTypeParameter)); - if (headMessage) { - diagnosticChainHead = chainDiagnosticMessages(diagnosticChainHead, headMessage); + if (fallbackError) { + diagnosticChainHead = chainDiagnosticMessages(diagnosticChainHead, fallbackError); } reportNoCommonSupertypeError(inferenceCandidates, (node).tagName || (node).expression || (node).tag, diagnosticChainHead); @@ -15376,8 +15376,8 @@ namespace ts { min = Math.min(min, getMinTypeArgumentCount(sig.typeParameters)); max = Math.max(max, length(sig.typeParameters)); } - const paramMessage = max > min ? `${min}-${max}` : min.toString(); - reportError(Diagnostics.Expected_0_type_arguments_but_got_1, paramMessage, typeArguments.length.toString()); + const paramCount = min < max ? `${min}-${max}` : min; + diagnostics.add(createDiagnosticForNode(node, Diagnostics.Expected_0_type_arguments_but_got_1, paramCount, typeArguments.length)); } else if (args) { let min = Number.POSITIVE_INFINITY; @@ -15386,7 +15386,6 @@ namespace ts { min = Math.min(min, sig.minArgumentCount); max = Math.max(max, sig.parameters.length); } - /////////// const hasRestParameter = some(signatures, sig => sig.hasRestParameter); const hasSpreadArgument = getSpreadArgumentIndex(args) > -1; const paramCount = hasRestParameter ? min : @@ -15397,10 +15396,10 @@ namespace ts { hasRestParameter ? Diagnostics.Expected_at_least_0_arguments_but_got_1 : hasSpreadArgument ? Diagnostics.Expected_0_arguments_but_got_a_minimum_of_1 : Diagnostics.Expected_0_arguments_but_got_1; - reportError(error, paramCount.toString(), argCount.toString()); + diagnostics.add(createDiagnosticForNode(node, error, paramCount, argCount)); } - else { - reportError(Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); + else if (fallbackError) { + diagnostics.add(createDiagnosticForNode(node, fallbackError)); } // No signature was applicable. We have already reported the errors for the invalid signature. @@ -15421,16 +15420,6 @@ namespace ts { return resolveErrorCall(node); - function reportError(message: DiagnosticMessage, arg0?: string, arg1?: string, arg2?: string): void { - let errorInfo: DiagnosticMessageChain; - errorInfo = chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2); - if (headMessage) { - errorInfo = chainDiagnosticMessages(errorInfo, headMessage); - } - - diagnostics.add(createDiagnosticForNodeFromMessageChain(node, errorInfo)); - } - function chooseOverload(candidates: Signature[], relation: Map, signatureHelpTrailingComma = false) { for (const originalCandidate of candidates) { if (!hasCorrectArity(node, args, originalCandidate, signatureHelpTrailingComma)) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 0f4d373c05b..14aea1bcd78 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1067,7 +1067,7 @@ "category": "Error", "code": 2345 }, - "Supplied parameters do not match any signature of call target.": { + "Call target does not contain any signatures.": { "category": "Error", "code": 2346 },