@@ -11672,7 +11672,7 @@ namespace ts {
11672
11672
}
11673
11673
11674
11674
function checkTypeRelatedToAndOptionallyElaborate(source: Type, target: Type, relation: Map<RelationComparisonResult>, errorNode: Node | undefined, expr: Expression | undefined, headMessage?: DiagnosticMessage, containingMessageChain?: () => DiagnosticMessageChain | undefined): boolean;
11675
- function checkTypeRelatedToAndOptionallyElaborate(source: Type, target: Type, relation: Map<RelationComparisonResult>, errorNode: Node | undefined, expr: Expression | undefined, headMessage?: DiagnosticMessage, containingMessageChain?: () => DiagnosticMessageChain | undefined, breakdown?: boolean): [Node, DiagnosticMessageChain];
11675
+ function checkTypeRelatedToAndOptionallyElaborate(source: Type, target: Type, relation: Map<RelationComparisonResult>, errorNode: Node | undefined, expr: Expression | undefined, headMessage?: DiagnosticMessage, containingMessageChain?: () => DiagnosticMessageChain | undefined, breakdown?: boolean): [Node, DiagnosticMessageChain] | false ;
11676
11676
function checkTypeRelatedToAndOptionallyElaborate(source: Type, target: Type, relation: Map<RelationComparisonResult>, errorNode: Node | undefined, expr: Expression | undefined, headMessage?: DiagnosticMessage, containingMessageChain?: () => DiagnosticMessageChain | undefined, breakdown?: boolean): boolean | [Node, DiagnosticMessageChain] {
11677
11677
if (isTypeRelatedTo(source, target, relation)) return breakdown ? false : true;
11678
11678
if (!errorNode || !elaborateError(expr, source, target, relation, headMessage)) {
@@ -12361,7 +12361,7 @@ namespace ts {
12361
12361
containingMessageChain?: () => DiagnosticMessageChain | undefined,
12362
12362
errorOutputContainer?: { error?: Diagnostic },
12363
12363
breakdown?: boolean
12364
- ): [Node, DiagnosticMessageChain];
12364
+ ): false | [Node, DiagnosticMessageChain];
12365
12365
/**
12366
12366
* Checks if 'source' is related to 'target' (e.g.: is a assignable to).
12367
12367
* @param source The left-hand-side of the relation.
@@ -21512,21 +21512,20 @@ namespace ts {
21512
21512
if (candidatesForArgumentError) {
21513
21513
if (candidatesForArgumentError.length > 3) {
21514
21514
const c = candidatesForArgumentError[candidatesForArgumentError.length - 1];
21515
- const chain = chainDiagnosticMessages(undefined, Diagnostics.Failed_to_find_a_suitable_overload_for_this_call);
21515
+ const chain = chainDiagnosticMessages(undefined, Diagnostics.Failed_to_find_a_suitable_overload_for_this_call_from_the_0_closest_overloads, candidatesForArgumentError.length);
21516
+
21516
21517
getSignatureApplicabilityError(node, args, c, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, () => chain);
21517
21518
}
21518
21519
else {
21519
- // const related: DiagnosticRelatedInformation[] = [];
21520
- for (const c of candidatesForArgumentError) {
21521
- const chain = chainDiagnosticMessages(chainDiagnosticMessages(undefined, Diagnostics.Overload_0_gave_the_following_error, signatureToString(c)), Diagnostics.Failed_to_find_a_suitable_overload_for_this_call);
21520
+ const related: DiagnosticRelatedInformation[] = [];
21521
+ const close = candidatesForArgumentError.filter(c => getMinArgumentCount(c) <= args.length && args.length <= getParameterCount(c));
21522
+ for (const c of close) {
21523
+ const chain = chainDiagnosticMessages(undefined, Diagnostics.Overload_0_gave_the_following_error, signatureToString(c));
21522
21524
const r = getSignatureApplicabilityError(node, args, c, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, () => chain);
21523
21525
if (!r || !r[0]) continue; // TODO:assert!
21524
- diagnostics.add(createDiagnosticForNodeFromMessageChain(r[0], r[1], /*relatedInformation*/ undefined));
21525
- // related.push(argNode)
21526
- // This is not right; I want them to be siblings
21527
- // probably this is a new feature :(
21528
- // chain = chainDiagnosticMessages(chain, msg);
21526
+ related.push(createDiagnosticForNodeFromMessageChain(r[0], r[1]));
21529
21527
}
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));
21530
21529
}
21531
21530
}
21532
21531
else if (candidateForArgumentArityError) {
@@ -21604,9 +21603,7 @@ namespace ts {
21604
21603
}
21605
21604
if (getSignatureApplicabilityError(node, args, checkCandidate, relation, argCheckMode, /*reportErrors*/ false, /*containingMessageChain*/ undefined)) {
21606
21605
// Give preference to error candidates that have no rest parameters (as they are more specific)
21607
- if (getMinArgumentCount(checkCandidate) <= args.length && args.length <= getParameterCount(checkCandidate)) {
21608
- (candidatesForArgumentError || (candidatesForArgumentError = [])).push(checkCandidate);
21609
- }
21606
+ (candidatesForArgumentError || (candidatesForArgumentError = [])).push(checkCandidate);
21610
21607
continue;
21611
21608
}
21612
21609
if (argCheckMode) {
@@ -21626,9 +21623,7 @@ namespace ts {
21626
21623
}
21627
21624
if (getSignatureApplicabilityError(node, args, checkCandidate, relation, argCheckMode, /*reportErrors*/ false, /*containingMessageChain*/ undefined)) {
21628
21625
// Give preference to error candidates that have no rest parameters (as they are more specific)
21629
- if (getMinArgumentCount(checkCandidate) <= args.length && args.length <= getParameterCount(checkCandidate)) {
21630
- (candidatesForArgumentError || (candidatesForArgumentError = [])).push(checkCandidate);
21631
- }
21626
+ (candidatesForArgumentError || (candidatesForArgumentError = [])).push(checkCandidate);
21632
21627
continue;
21633
21628
}
21634
21629
}
0 commit comments