mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Do not report multiple diagnostics per signature.
If there are multiple diagnostics per signature, choose the signature with the fewer diagnostics to report. If there are more than one with the minimum, choose the latest in the overload set.
This commit is contained in:
+14
-4
@@ -21632,19 +21632,29 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
else {
|
||||
const related: DiagnosticRelatedInformation[] = [];
|
||||
const allDiagnostics: DiagnosticRelatedInformation[][] = [];
|
||||
let max = 0;
|
||||
let min = Number.MAX_VALUE;
|
||||
let minIndex = 0;
|
||||
let i = 0;
|
||||
for (const c of candidatesForArgumentError) {
|
||||
i++;
|
||||
const chain = () => chainDiagnosticMessages(/*details*/ undefined, Diagnostics.Overload_0_of_1_2_gave_the_following_error, i, candidates.length, signatureToString(c));
|
||||
const chain = () => chainDiagnosticMessages(/*details*/ undefined, Diagnostics.Overload_0_of_1_2_gave_the_following_error, i + 1, candidates.length, signatureToString(c));
|
||||
const diags = getSignatureApplicabilityError(node, args, c, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, chain);
|
||||
if (diags) {
|
||||
related.push(...diags);
|
||||
if (diags.length <= min) {
|
||||
min = diags.length;
|
||||
minIndex = i;
|
||||
}
|
||||
max = Math.max(max, diags.length);
|
||||
allDiagnostics.push(diags);
|
||||
}
|
||||
else {
|
||||
Debug.fail("No error for 3 or fewer overload signatures");
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
const related = max > 1 ? allDiagnostics[minIndex] : flatten(allDiagnostics);
|
||||
diagnostics.add(createDiagnosticForNodeFromMessageChain(node, chainDiagnosticMessages(/*details*/ undefined, Diagnostics.No_overload_matches_this_call), related));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -600,6 +600,7 @@ namespace ts {
|
||||
*
|
||||
* @param array The array to flatten.
|
||||
*/
|
||||
export function flatten<T>(array: T[][]): T[];
|
||||
export function flatten<T>(array: ReadonlyArray<T | ReadonlyArray<T> | undefined>): T[];
|
||||
export function flatten<T>(array: ReadonlyArray<T | ReadonlyArray<T> | undefined> | undefined): T[] | undefined;
|
||||
export function flatten<T>(array: ReadonlyArray<T | ReadonlyArray<T> | undefined> | undefined): T[] | undefined {
|
||||
|
||||
@@ -2625,14 +2625,6 @@
|
||||
"category": "Error",
|
||||
"code": 2755
|
||||
},
|
||||
"The closest overload gave the following error.": {
|
||||
"category": "Error",
|
||||
"code": 2756
|
||||
},
|
||||
"The closest overload is declared here.": {
|
||||
"category": "Error",
|
||||
"code": 2757
|
||||
},
|
||||
"The last overload gave the following error.": {
|
||||
"category": "Error",
|
||||
"code": 2758
|
||||
|
||||
@@ -8092,7 +8092,7 @@ namespace ts {
|
||||
visitDirectory(basePath, combinePaths(currentDirectory, basePath), depth);
|
||||
}
|
||||
|
||||
return flatten<string>(results);
|
||||
return flatten(results);
|
||||
|
||||
function visitDirectory(path: string, absolutePath: string, depth: number | undefined) {
|
||||
const canonicalPath = toCanonical(realpath(absolutePath));
|
||||
|
||||
@@ -15,11 +15,5 @@ tests/cases/compiler/heterogeneousArrayAndOverloads.ts(9,9): error TS2755: No ov
|
||||
!!! error TS2755: No overload matches this call.
|
||||
!!! related TS2760 tests/cases/compiler/heterogeneousArrayAndOverloads.ts:9:26: Overload 1 of 2, '(arg1: number[]): any', gave the following error.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
!!! related TS2760 tests/cases/compiler/heterogeneousArrayAndOverloads.ts:9:20: Overload 2 of 2, '(arg1: string[]): any', gave the following error.
|
||||
Type 'number' is not assignable to type 'string'.
|
||||
!!! related TS2760 tests/cases/compiler/heterogeneousArrayAndOverloads.ts:9:23: Overload 2 of 2, '(arg1: string[]): any', gave the following error.
|
||||
Type 'number' is not assignable to type 'string'.
|
||||
!!! related TS2760 tests/cases/compiler/heterogeneousArrayAndOverloads.ts:9:32: Overload 2 of 2, '(arg1: string[]): any', gave the following error.
|
||||
Type 'number' is not assignable to type 'string'.
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user