Skip to content

Commit 720ad5b

Browse files
committed
Improve error message and update baselines
1 parent b85796c commit 720ad5b

34 files changed

+1027
-509
lines changed

src/compiler/checker.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21120,13 +21120,20 @@ namespace ts {
2112021120
* @param signature a candidate signature we are trying whether it is a call signature
2112121121
* @param relation a relationship to check parameter and argument type
2112221122
*/
21123-
function checkApplicableSignatureForJsxOpeningLikeElement(node: JsxOpeningLikeElement, signature: Signature, relation: Map<RelationComparisonResult>, checkMode: CheckMode, reportErrors: boolean) {
21123+
function checkApplicableSignatureForJsxOpeningLikeElement(
21124+
node: JsxOpeningLikeElement,
21125+
signature: Signature,
21126+
relation: Map<RelationComparisonResult>,
21127+
checkMode: CheckMode,
21128+
reportErrors: boolean,
21129+
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
21130+
) {
2112421131
// Stateless function components can have maximum of three arguments: "props", "context", and "updater".
2112521132
// However "context" and "updater" are implicit and can't be specify by users. Only the first parameter, props,
2112621133
// can be specified by users through attributes property.
2112721134
const paramType = getEffectiveFirstArgumentForJsxSignature(signature, node);
2112821135
const attributesType = checkExpressionWithContextualType(node.attributes, paramType, /*inferenceContext*/ undefined, checkMode);
21129-
return checkTypeRelatedToAndOptionallyElaborate(attributesType, paramType, relation, reportErrors ? node.tagName : undefined, node.attributes, undefined, undefined, /*breakdown*/ true);
21136+
return checkTypeRelatedToAndOptionallyElaborate(attributesType, paramType, relation, reportErrors ? node.tagName : undefined, node.attributes, undefined, containingMessageChain, /*breakdown*/ true);
2113021137
}
2113121138

2113221139
function getSignatureApplicabilityError(
@@ -21139,8 +21146,7 @@ namespace ts {
2113921146
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
2114021147
) {
2114121148
if (isJsxOpeningLikeElement(node)) {
21142-
// TODO: Maybe containingMessageChain too?
21143-
return checkApplicableSignatureForJsxOpeningLikeElement(node, signature, relation, checkMode, reportErrors);
21149+
return checkApplicableSignatureForJsxOpeningLikeElement(node, signature, relation, checkMode, reportErrors, containingMessageChain);
2114421150
}
2114521151
const thisType = getThisTypeOfSignature(signature);
2114621152
if (thisType && thisType !== voidType && node.kind !== SyntaxKind.NewExpression) {
@@ -21151,7 +21157,7 @@ namespace ts {
2115121157
const thisArgumentType = thisArgumentNode ? checkExpression(thisArgumentNode) : voidType;
2115221158
const errorNode = reportErrors ? (thisArgumentNode || node) : undefined;
2115321159
const headMessage = Diagnostics.The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1;
21154-
const r = checkTypeRelatedTo(thisArgumentType, thisType, relation, errorNode, headMessage, undefined, undefined, /*breakdown*/ true);
21160+
const r = checkTypeRelatedTo(thisArgumentType, thisType, relation, errorNode, headMessage, containingMessageChain, undefined, /*breakdown*/ true);
2115521161
if (r) {
2115621162
return r;
2115721163
}
@@ -21512,7 +21518,7 @@ namespace ts {
2151221518
let chain: DiagnosticMessageChain | undefined = undefined;
2151321519
if (candidatesForArgumentError.length > 3) {
2151421520
chain = chainDiagnosticMessages(chain, Diagnostics.The_last_overload_gave_the_following_error);
21515-
chain = chainDiagnosticMessages(chain, Diagnostics.Failed_to_find_a_suitable_overload_for_this_call_from_0_overloads, candidatesForArgumentError.length);
21521+
chain = chainDiagnosticMessages(chain, Diagnostics.No_suitable_overload_for_this_call);
2151621522
}
2151721523
const r = getSignatureApplicabilityError(node, args, last, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, () => chain);
2151821524
Debug.assert(!!r && !!r[0], "No error for last signature");
@@ -21522,15 +21528,17 @@ namespace ts {
2152221528
}
2152321529
else {
2152421530
const related: DiagnosticRelatedInformation[] = [];
21531+
let i = 0;
2152521532
for (const c of candidatesForArgumentError) {
21526-
const chain = chainDiagnosticMessages(undefined, Diagnostics.Overload_0_gave_the_following_error, signatureToString(c));
21533+
i++;
21534+
const chain = chainDiagnosticMessages(undefined, Diagnostics.Overload_0_of_1_2_gave_the_following_error, i, candidates.length, signatureToString(c));
2152721535
const r = getSignatureApplicabilityError(node, args, c, assignableRelation, CheckMode.Normal, /*reportErrors*/ true, () => chain);
2152821536
Debug.assert(!!r && !!r[0], "No error for signature (1)");
2152921537
if (r) {
2153021538
related.push(createDiagnosticForNodeFromMessageChain(...r));
2153121539
}
2153221540
}
21533-
diagnostics.add(createDiagnosticForNodeFromMessageChain(node, chainDiagnosticMessages(undefined, Diagnostics.Failed_to_find_a_suitable_overload_for_this_call_from_0_overloads, candidatesForArgumentError.length), related));
21541+
diagnostics.add(createDiagnosticForNodeFromMessageChain(node, chainDiagnosticMessages(undefined, Diagnostics.No_suitable_overload_for_this_call), related));
2153421542
}
2153521543
}
2153621544
else if (candidateForArgumentArityError) {

src/compiler/diagnosticMessages.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2621,15 +2621,15 @@
26212621
"category": "Error",
26222622
"code": 2754
26232623
},
2624-
"Failed to find a suitable overload for this call from {0} overloads.": {
2624+
"No suitable overload for this call.": {
26252625
"category": "Error",
26262626
"code": 2755
26272627
},
26282628
"The last overload gave the following error.": {
26292629
"category": "Error",
26302630
"code": 2756
26312631
},
2632-
"Overload '{0}' gave the following error.": {
2632+
"Overload {0} of {1}, '{2}', gave the following error.": {
26332633
"category": "Error",
26342634
"code": 2757
26352635
},

tests/baselines/reference/bigintWithLib.errors.txt

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +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,33): error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'ArrayBuffer | SharedArrayBuffer'.
3-
Type 'number[]' is missing the following properties from type 'SharedArrayBuffer': byteLength, [Symbol.species], [Symbol.toStringTag]
2+
tests/cases/compiler/bigintWithLib.ts(16,15): error TS2755: No suitable overload for this call.
43
tests/cases/compiler/bigintWithLib.ts(21,13): error TS2540: Cannot assign to 'length' because it is a read-only property.
5-
tests/cases/compiler/bigintWithLib.ts(28,35): error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'ArrayBuffer | SharedArrayBuffer'.
6-
Type 'number[]' is not assignable to type 'SharedArrayBuffer'.
4+
tests/cases/compiler/bigintWithLib.ts(28,16): error TS2755: No suitable overload for this call.
75
tests/cases/compiler/bigintWithLib.ts(33,13): error TS2540: Cannot assign to 'length' because it is a read-only property.
86
tests/cases/compiler/bigintWithLib.ts(40,25): error TS2345: Argument of type '-1' is not assignable to parameter of type 'bigint'.
97
tests/cases/compiler/bigintWithLib.ts(43,26): error TS2345: Argument of type '123' is not assignable to parameter of type 'bigint'.
@@ -28,9 +26,22 @@ tests/cases/compiler/bigintWithLib.ts(43,26): error TS2345: Argument of type '12
2826
bigIntArray = new BigInt64Array(10);
2927
bigIntArray = new BigInt64Array([1n, 2n, 3n]);
3028
bigIntArray = new BigInt64Array([1, 2, 3]); // should error
31-
~~~~~~~~~
32-
!!! error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'ArrayBuffer | SharedArrayBuffer'.
33-
!!! error TS2345: Type 'number[]' is missing the following properties from type 'SharedArrayBuffer': byteLength, [Symbol.species], [Symbol.toStringTag]
29+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
32+
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.
34+
Argument of type 'number[]' is not assignable to parameter of type 'Iterable<bigint>'.
35+
Types of property '[Symbol.iterator]' are incompatible.
36+
Type '() => IterableIterator<number>' is not assignable to type '() => Iterator<bigint>'.
37+
Type 'IterableIterator<number>' is not assignable to type 'Iterator<bigint>'.
38+
Types of property 'next' are incompatible.
39+
Type '(value?: any) => IteratorResult<number>' is not assignable to type '(value?: any) => IteratorResult<bigint>'.
40+
Type 'IteratorResult<number>' is not assignable to type 'IteratorResult<bigint>'.
41+
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.
43+
Argument of type 'number[]' is not assignable to parameter of type 'ArrayBuffer | SharedArrayBuffer'.
44+
Type 'number[]' is missing the following properties from type 'SharedArrayBuffer': byteLength, [Symbol.species], [Symbol.toStringTag]
3445
bigIntArray = new BigInt64Array(new ArrayBuffer(80));
3546
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8);
3647
bigIntArray = new BigInt64Array(new ArrayBuffer(80), 8, 3);
@@ -45,9 +56,15 @@ tests/cases/compiler/bigintWithLib.ts(43,26): error TS2345: Argument of type '12
4556
bigUintArray = new BigUint64Array(10);
4657
bigUintArray = new BigUint64Array([1n, 2n, 3n]);
4758
bigUintArray = new BigUint64Array([1, 2, 3]); // should error
48-
~~~~~~~~~
49-
!!! error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'ArrayBuffer | SharedArrayBuffer'.
50-
!!! error TS2345: Type 'number[]' is not assignable to type 'SharedArrayBuffer'.
59+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
62+
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.
64+
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.
66+
Argument of type 'number[]' is not assignable to parameter of type 'ArrayBuffer | SharedArrayBuffer'.
67+
Type 'number[]' is not assignable to type 'SharedArrayBuffer'.
5168
bigUintArray = new BigUint64Array(new ArrayBuffer(80));
5269
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8);
5370
bigUintArray = new BigUint64Array(new ArrayBuffer(80), 8, 3);

tests/baselines/reference/checkJsxChildrenCanBeTupleType.errors.txt

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
tests/cases/conformance/jsx/checkJsxChildrenCanBeTupleType.tsx(17,18): error TS2322: Type '{ children: [Element, Element, Element]; }' is not assignable to type 'Readonly<ResizablePanelProps>'.
2-
Types of property 'children' are incompatible.
3-
Type '[Element, Element, Element]' is not assignable to type '[ReactNode, ReactNode]'.
4-
Types of property 'length' are incompatible.
5-
Type '3' is not assignable to type '2'.
1+
tests/cases/conformance/jsx/checkJsxChildrenCanBeTupleType.tsx(17,17): error TS2755: No suitable overload for this call.
62

73

84
==== tests/cases/conformance/jsx/checkJsxChildrenCanBeTupleType.tsx (1 errors) ====
@@ -23,12 +19,18 @@ tests/cases/conformance/jsx/checkJsxChildrenCanBeTupleType.tsx(17,18): error TS2
2319
</ResizablePanel>
2420

2521
const testErr = <ResizablePanel>
26-
~~~~~~~~~~~~~~
27-
!!! error TS2322: Type '{ children: [Element, Element, Element]; }' is not assignable to type 'Readonly<ResizablePanelProps>'.
28-
!!! error TS2322: Types of property 'children' are incompatible.
29-
!!! error TS2322: Type '[Element, Element, Element]' is not assignable to type '[ReactNode, ReactNode]'.
30-
!!! error TS2322: Types of property 'length' are incompatible.
31-
!!! error TS2322: Type '3' is not assignable to type '2'.
22+
~~~~~~~~~~~~~~~~
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.
25+
Type '{ children: [Element, Element, Element]; }' is not assignable to type 'Readonly<ResizablePanelProps>'.
26+
Types of property 'children' are incompatible.
27+
Type '[Element, Element, Element]' is not assignable to type '[ReactNode, ReactNode]'.
28+
Types of property 'length' are incompatible.
29+
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.
31+
Type '{ children: [Element, Element, Element]; }' is not assignable to type 'Readonly<ResizablePanelProps>'.
32+
Types of property 'children' are incompatible.
33+
Type '[Element, Element, Element]' is not assignable to type '[ReactNode, ReactNode]'.
3234
<div />
3335
<div />
3436
<div />

tests/baselines/reference/constructorOverloads1.errors.txt

Lines changed: 14 additions & 6 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,18): error TS2345: Argument of type 'Foo' is not assignable to parameter of type 'number'.
6-
tests/cases/compiler/constructorOverloads1.ts(17,18): error TS2345: Argument of type 'any[]' is not assignable to parameter of type 'number'.
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.
77

88

99
==== tests/cases/compiler/constructorOverloads1.ts (6 errors) ====
@@ -35,11 +35,19 @@ tests/cases/compiler/constructorOverloads1.ts(17,18): error TS2345: Argument of
3535
var f1 = new Foo("hey");
3636
var f2 = new Foo(0);
3737
var f3 = new Foo(f1);
38-
~~
39-
!!! error TS2345: Argument of type 'Foo' is not assignable to parameter of type 'number'.
38+
~~~~~~~~~~~
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.
41+
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.
43+
Argument of type 'Foo' is not assignable to parameter of type 'number'.
4044
var f4 = new Foo([f1,f2,f3]);
41-
~~~~~~~~~~
42-
!!! error TS2345: Argument of type 'any[]' is not assignable to parameter of type 'number'.
45+
~~~~~~~~~~~~~~~~~~~
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.
48+
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.
50+
Argument of type 'any[]' is not assignable to parameter of type 'number'.
4351

4452
f1.bar1();
4553
f1.bar2();

0 commit comments

Comments
 (0)