@@ -21510,22 +21510,30 @@ namespace ts {
21510
21510
// skip the checkApplicableSignature check.
21511
21511
if (reportErrors) {
21512
21512
if (candidatesForArgumentError) {
21513
- if (candidatesForArgumentError.length > 3) {
21514
- const c = candidatesForArgumentError[candidatesForArgumentError.length - 1];
21515
- const chain = chainDiagnosticMessages(undefined, Diagnostics.Failed_to_find_a_suitable_overload_for_this_call_from_the_0_closest_overloads, candidatesForArgumentError.length);
21516
-
21517
- getSignatureApplicabilityError(node, args, c, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, () => chain);
21513
+ if (candidatesForArgumentError.length === 1 || candidatesForArgumentError.length > 3) {
21514
+ const last = candidatesForArgumentError[candidatesForArgumentError.length - 1];
21515
+ let chain: DiagnosticMessageChain | undefined = undefined;
21516
+ if (candidatesForArgumentError.length > 3) {
21517
+ chain = chainDiagnosticMessages(chain, Diagnostics.The_last_overload_gave_the_following_error);
21518
+ chain = chainDiagnosticMessages(chain, Diagnostics.Failed_to_find_a_suitable_overload_for_this_call_from_0_overloads, candidatesForArgumentError.length);
21519
+ }
21520
+ const r = getSignatureApplicabilityError(node, args, last, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, () => chain);
21521
+ Debug.assert(!!r && !!r[0]);
21522
+ if (r) {
21523
+ diagnostics.add(createDiagnosticForNodeFromMessageChain(r[0], r[1], undefined));
21524
+ }
21518
21525
}
21519
21526
else {
21520
21527
const related: DiagnosticRelatedInformation[] = [];
21521
- const close = candidatesForArgumentError.filter(c => getMinArgumentCount(c) <= args.length && args.length <= getParameterCount(c));
21522
- for (const c of close) {
21528
+ for (const c of candidatesForArgumentError) {
21523
21529
const chain = chainDiagnosticMessages(undefined, Diagnostics.Overload_0_gave_the_following_error, signatureToString(c));
21524
21530
const r = getSignatureApplicabilityError(node, args, c, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, () => chain);
21525
- if (!r || !r[0]) continue; // TODO:assert!
21526
- related.push(createDiagnosticForNodeFromMessageChain(r[0], r[1]));
21531
+ Debug.assert(!!r && !!r[0]);
21532
+ if (r) {
21533
+ related.push(createDiagnosticForNodeFromMessageChain(r[0], r[1]));
21534
+ }
21527
21535
}
21528
- diagnostics.add(createDiagnosticForNodeFromMessageChain(node, chainDiagnosticMessages(undefined, Diagnostics.Failed_to_find_a_suitable_overload_for_this_call_from_the_0_closest_overloads, close .length), related));
21536
+ diagnostics.add(createDiagnosticForNodeFromMessageChain(node, chainDiagnosticMessages(undefined, Diagnostics.Failed_to_find_a_suitable_overload_for_this_call_from_0_overloads, candidatesForArgumentError .length), related));
21529
21537
}
21530
21538
}
21531
21539
else if (candidateForArgumentArityError) {
0 commit comments