Skip to content

Commit 68968fd

Browse files
committed
Improve error messages and related spans
1 parent b58932e commit 68968fd

File tree

46 files changed

+615
-536
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+615
-536
lines changed

src/compiler/checker.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21609,18 +21609,19 @@ namespace ts {
2160921609
let chain: DiagnosticMessageChain | undefined;
2161021610
if (candidatesForArgumentError.length > 3) {
2161121611
chain = chainDiagnosticMessages(chain, Diagnostics.The_last_overload_gave_the_following_error);
21612-
chain = chainDiagnosticMessages(chain, Diagnostics.No_suitable_overload_for_this_call);
21612+
chain = chainDiagnosticMessages(chain, Diagnostics.No_overload_matches_this_call);
2161321613
}
21614-
const ds = getSignatureApplicabilityError(node, args, last, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, () => chain);
21615-
if (ds) {
21616-
// if elaboration already displayed the error, don't do anything extra
21617-
// note that we could do this always here, but getSignatureApplicabilityError is currently not configured to do that
21618-
for (const d of ds) {
21614+
const diags = getSignatureApplicabilityError(node, args, last, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, () => chain);
21615+
if (diags) {
21616+
for (const d of diags) {
21617+
if (last.declaration && candidatesForArgumentError.length > 3) {
21618+
addRelatedInfo(d, createDiagnosticForNode(last.declaration, Diagnostics.The_last_overload_is_declared_here));
21619+
}
2161921620
diagnostics.add(d);
2162021621
}
2162121622
}
2162221623
else {
21623-
Debug.assert(false, "No error for last overload signature");
21624+
Debug.fail("No error for last overload signature");
2162421625
}
2162521626
}
2162621627
else {
@@ -21629,15 +21630,15 @@ namespace ts {
2162921630
for (const c of candidatesForArgumentError) {
2163021631
i++;
2163121632
const chain = () => chainDiagnosticMessages(/*details*/ undefined, Diagnostics.Overload_0_of_1_2_gave_the_following_error, i, candidates.length, signatureToString(c));
21632-
const ds = getSignatureApplicabilityError(node, args, c, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, chain);
21633-
if (ds) {
21634-
related.push(...ds);
21633+
const diags = getSignatureApplicabilityError(node, args, c, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, chain);
21634+
if (diags) {
21635+
related.push(...diags);
2163521636
}
2163621637
else {
21637-
Debug.assert(false, "No error for 3 or fewer overload signatures");
21638+
Debug.fail("No error for 3 or fewer overload signatures");
2163821639
}
2163921640
}
21640-
diagnostics.add(createDiagnosticForNodeFromMessageChain(node, chainDiagnosticMessages(/*details*/ undefined, Diagnostics.No_suitable_overload_for_this_call), related));
21641+
diagnostics.add(createDiagnosticForNodeFromMessageChain(node, chainDiagnosticMessages(/*details*/ undefined, Diagnostics.No_overload_matches_this_call), related));
2164121642
}
2164221643
}
2164321644
else if (candidateForArgumentArityError) {

src/compiler/diagnosticMessages.json

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2621,18 +2621,30 @@
26212621
"category": "Error",
26222622
"code": 2754
26232623
},
2624-
"No suitable overload for this call.": {
2624+
"No overload matches this call.": {
26252625
"category": "Error",
26262626
"code": 2755
26272627
},
2628-
"The last overload gave the following error.": {
2628+
"The closest overload gave the following error.": {
26292629
"category": "Error",
26302630
"code": 2756
26312631
},
2632-
"Overload {0} of {1}, '{2}', gave the following error.": {
2632+
"The closest overload is declared here.": {
26332633
"category": "Error",
26342634
"code": 2757
26352635
},
2636+
"The last overload gave the following error.": {
2637+
"category": "Error",
2638+
"code": 2758
2639+
},
2640+
"The last overload is declared here.": {
2641+
"category": "Error",
2642+
"code": 2759
2643+
},
2644+
"Overload {0} of {1}, '{2}', gave the following error.": {
2645+
"category": "Error",
2646+
"code": 2760
2647+
},
26362648

26372649
"Import declaration '{0}' is using private name '{1}'.": {
26382650
"category": "Error",

tests/baselines/reference/bigintWithLib.errors.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
tests/cases/compiler/bigintWithLib.ts(4,1): error TS2350: Only a void function can be called with the 'new' keyword.
2-
tests/cases/compiler/bigintWithLib.ts(16,15): error TS2755: No suitable overload for this call.
2+
tests/cases/compiler/bigintWithLib.ts(16,15): error TS2755: No overload matches this call.
33
tests/cases/compiler/bigintWithLib.ts(21,13): error TS2540: Cannot assign to 'length' because it is a read-only property.
4-
tests/cases/compiler/bigintWithLib.ts(28,16): error TS2755: No suitable overload for this call.
4+
tests/cases/compiler/bigintWithLib.ts(28,16): error TS2755: No overload matches this call.
55
tests/cases/compiler/bigintWithLib.ts(33,13): error TS2540: Cannot assign to 'length' because it is a read-only property.
66
tests/cases/compiler/bigintWithLib.ts(40,25): error TS2345: Argument of type '-1' is not assignable to parameter of type 'bigint'.
77
tests/cases/compiler/bigintWithLib.ts(43,26): error TS2345: Argument of type '123' is not assignable to parameter of type 'bigint'.
@@ -27,10 +27,10 @@ tests/cases/compiler/bigintWithLib.ts(43,26): error TS2345: Argument of type '12
2727
bigIntArray = new BigInt64Array([1n, 2n, 3n]);
2828
bigIntArray = new BigInt64Array([1, 2, 3]); // should error
2929
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
30-
!!! error TS2755: No suitable overload for this call.
31-
!!! related TS2757 tests/cases/compiler/bigintWithLib.ts:16:33: Overload 1 of 3, '(length?: number): BigInt64Array', gave the following error.
30+
!!! error TS2755: No overload matches this call.
31+
!!! related TS2760 tests/cases/compiler/bigintWithLib.ts:16:33: Overload 1 of 3, '(length?: number): BigInt64Array', gave the following error.
3232
Argument of type 'number[]' is not assignable to parameter of type 'number'.
33-
!!! related TS2757 tests/cases/compiler/bigintWithLib.ts:16:33: Overload 2 of 3, '(array: Iterable<bigint>): BigInt64Array', gave the following error.
33+
!!! related TS2760 tests/cases/compiler/bigintWithLib.ts:16:33: Overload 2 of 3, '(array: Iterable<bigint>): BigInt64Array', gave the following error.
3434
Argument of type 'number[]' is not assignable to parameter of type 'Iterable<bigint>'.
3535
Types of property '[Symbol.iterator]' are incompatible.
3636
Type '() => IterableIterator<number>' is not assignable to type '() => Iterator<bigint>'.
@@ -39,7 +39,7 @@ tests/cases/compiler/bigintWithLib.ts(43,26): error TS2345: Argument of type '12
3939
Type '(value?: any) => IteratorResult<number>' is not assignable to type '(value?: any) => IteratorResult<bigint>'.
4040
Type 'IteratorResult<number>' is not assignable to type 'IteratorResult<bigint>'.
4141
Type 'number' is not assignable to type 'bigint'.
42-
!!! related TS2757 tests/cases/compiler/bigintWithLib.ts:16:33: Overload 3 of 3, '(buffer: ArrayBuffer | SharedArrayBuffer, byteOffset?: number, length?: number): BigInt64Array', gave the following error.
42+
!!! related TS2760 tests/cases/compiler/bigintWithLib.ts:16:33: Overload 3 of 3, '(buffer: ArrayBuffer | SharedArrayBuffer, byteOffset?: number, length?: number): BigInt64Array', gave the following error.
4343
Argument of type 'number[]' is not assignable to parameter of type 'ArrayBuffer | SharedArrayBuffer'.
4444
Type 'number[]' is missing the following properties from type 'SharedArrayBuffer': byteLength, [Symbol.species], [Symbol.toStringTag]
4545
bigIntArray = new BigInt64Array(new ArrayBuffer(80));
@@ -57,12 +57,12 @@ tests/cases/compiler/bigintWithLib.ts(43,26): error TS2345: Argument of type '12
5757
bigUintArray = new BigUint64Array([1n, 2n, 3n]);
5858
bigUintArray = new BigUint64Array([1, 2, 3]); // should error
5959
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
60-
!!! error TS2755: No suitable overload for this call.
61-
!!! related TS2757 tests/cases/compiler/bigintWithLib.ts:28:35: Overload 1 of 3, '(length?: number): BigUint64Array', gave the following error.
60+
!!! error TS2755: No overload matches this call.
61+
!!! related TS2760 tests/cases/compiler/bigintWithLib.ts:28:35: Overload 1 of 3, '(length?: number): BigUint64Array', gave the following error.
6262
Argument of type 'number[]' is not assignable to parameter of type 'number'.
63-
!!! related TS2757 tests/cases/compiler/bigintWithLib.ts:28:35: Overload 2 of 3, '(array: Iterable<bigint>): BigUint64Array', gave the following error.
63+
!!! related TS2760 tests/cases/compiler/bigintWithLib.ts:28:35: Overload 2 of 3, '(array: Iterable<bigint>): BigUint64Array', gave the following error.
6464
Argument of type 'number[]' is not assignable to parameter of type 'Iterable<bigint>'.
65-
!!! related TS2757 tests/cases/compiler/bigintWithLib.ts:28:35: Overload 3 of 3, '(buffer: ArrayBuffer | SharedArrayBuffer, byteOffset?: number, length?: number): BigUint64Array', gave the following error.
65+
!!! related TS2760 tests/cases/compiler/bigintWithLib.ts:28:35: Overload 3 of 3, '(buffer: ArrayBuffer | SharedArrayBuffer, byteOffset?: number, length?: number): BigUint64Array', gave the following error.
6666
Argument of type 'number[]' is not assignable to parameter of type 'ArrayBuffer | SharedArrayBuffer'.
6767
Type 'number[]' is not assignable to type 'SharedArrayBuffer'.
6868
bigUintArray = new BigUint64Array(new ArrayBuffer(80));

tests/baselines/reference/checkJsxChildrenCanBeTupleType.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/conformance/jsx/checkJsxChildrenCanBeTupleType.tsx(17,17): error TS2755: No suitable overload for this call.
1+
tests/cases/conformance/jsx/checkJsxChildrenCanBeTupleType.tsx(17,17): error TS2755: No overload matches this call.
22

33

44
==== tests/cases/conformance/jsx/checkJsxChildrenCanBeTupleType.tsx (1 errors) ====
@@ -20,14 +20,14 @@ tests/cases/conformance/jsx/checkJsxChildrenCanBeTupleType.tsx(17,17): error TS2
2020

2121
const testErr = <ResizablePanel>
2222
~~~~~~~~~~~~~~~~
23-
!!! error TS2755: No suitable overload for this call.
24-
!!! related TS2757 tests/cases/conformance/jsx/checkJsxChildrenCanBeTupleType.tsx:17:18: Overload 1 of 2, '(props: Readonly<ResizablePanelProps>): ResizablePanel', gave the following error.
23+
!!! error TS2755: No overload matches this call.
24+
!!! related TS2760 tests/cases/conformance/jsx/checkJsxChildrenCanBeTupleType.tsx:17:18: Overload 1 of 2, '(props: Readonly<ResizablePanelProps>): ResizablePanel', gave the following error.
2525
Type '{ children: [Element, Element, Element]; }' is not assignable to type 'Readonly<ResizablePanelProps>'.
2626
Types of property 'children' are incompatible.
2727
Type '[Element, Element, Element]' is not assignable to type '[ReactNode, ReactNode]'.
2828
Types of property 'length' are incompatible.
2929
Type '3' is not assignable to type '2'.
30-
!!! related TS2757 tests/cases/conformance/jsx/checkJsxChildrenCanBeTupleType.tsx:17:18: Overload 2 of 2, '(props: ResizablePanelProps, context?: any): ResizablePanel', gave the following error.
30+
!!! related TS2760 tests/cases/conformance/jsx/checkJsxChildrenCanBeTupleType.tsx:17:18: Overload 2 of 2, '(props: ResizablePanelProps, context?: any): ResizablePanel', gave the following error.
3131
Type '{ children: [Element, Element, Element]; }' is not assignable to type 'Readonly<ResizablePanelProps>'.
3232
Types of property 'children' are incompatible.
3333
Type '[Element, Element, Element]' is not assignable to type '[ReactNode, ReactNode]'.

tests/baselines/reference/constructorOverloads1.errors.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ tests/cases/compiler/constructorOverloads1.ts(2,5): error TS2392: Multiple const
22
tests/cases/compiler/constructorOverloads1.ts(3,5): error TS2392: Multiple constructor implementations are not allowed.
33
tests/cases/compiler/constructorOverloads1.ts(4,5): error TS2392: Multiple constructor implementations are not allowed.
44
tests/cases/compiler/constructorOverloads1.ts(7,5): error TS2392: Multiple constructor implementations are not allowed.
5-
tests/cases/compiler/constructorOverloads1.ts(16,10): error TS2755: No suitable overload for this call.
6-
tests/cases/compiler/constructorOverloads1.ts(17,10): error TS2755: No suitable overload for this call.
5+
tests/cases/compiler/constructorOverloads1.ts(16,10): error TS2755: No overload matches this call.
6+
tests/cases/compiler/constructorOverloads1.ts(17,10): error TS2755: No overload matches this call.
77

88

99
==== tests/cases/compiler/constructorOverloads1.ts (6 errors) ====
@@ -36,17 +36,17 @@ tests/cases/compiler/constructorOverloads1.ts(17,10): error TS2755: No suitable
3636
var f2 = new Foo(0);
3737
var f3 = new Foo(f1);
3838
~~~~~~~~~~~
39-
!!! error TS2755: No suitable overload for this call.
40-
!!! related TS2757 tests/cases/compiler/constructorOverloads1.ts:16:18: Overload 1 of 2, '(s: string): Foo', gave the following error.
39+
!!! error TS2755: No overload matches this call.
40+
!!! related TS2760 tests/cases/compiler/constructorOverloads1.ts:16:18: Overload 1 of 2, '(s: string): Foo', gave the following error.
4141
Argument of type 'Foo' is not assignable to parameter of type 'string'.
42-
!!! related TS2757 tests/cases/compiler/constructorOverloads1.ts:16:18: Overload 2 of 2, '(n: number): Foo', gave the following error.
42+
!!! related TS2760 tests/cases/compiler/constructorOverloads1.ts:16:18: Overload 2 of 2, '(n: number): Foo', gave the following error.
4343
Argument of type 'Foo' is not assignable to parameter of type 'number'.
4444
var f4 = new Foo([f1,f2,f3]);
4545
~~~~~~~~~~~~~~~~~~~
46-
!!! error TS2755: No suitable overload for this call.
47-
!!! related TS2757 tests/cases/compiler/constructorOverloads1.ts:17:18: Overload 1 of 2, '(s: string): Foo', gave the following error.
46+
!!! error TS2755: No overload matches this call.
47+
!!! related TS2760 tests/cases/compiler/constructorOverloads1.ts:17:18: Overload 1 of 2, '(s: string): Foo', gave the following error.
4848
Argument of type 'any[]' is not assignable to parameter of type 'string'.
49-
!!! related TS2757 tests/cases/compiler/constructorOverloads1.ts:17:18: Overload 2 of 2, '(n: number): Foo', gave the following error.
49+
!!! related TS2760 tests/cases/compiler/constructorOverloads1.ts:17:18: Overload 2 of 2, '(n: number): Foo', gave the following error.
5050
Argument of type 'any[]' is not assignable to parameter of type 'number'.
5151

5252
f1.bar1();

0 commit comments

Comments
 (0)