Skip to content

Commit f139455

Browse files
committed
Address PR comments
1 parent 1906142 commit f139455

11 files changed

+58
-41
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21693,10 +21693,10 @@ namespace ts {
2169321693
i++;
2169421694
}
2169521695

21696-
const related = map(
21697-
max > 1 ? allDiagnostics[minIndex] : flatten(allDiagnostics),
21698-
d => typeof d.messageText === "string" ? (d as DiagnosticMessageChain) : d.messageText);
21699-
diagnostics.add(createDiagnosticForNodeFromMessageChain(node, chainDiagnosticMessages(related, Diagnostics.No_overload_matches_this_call)));
21696+
const diags = max > 1 ? allDiagnostics[minIndex] : flatten(allDiagnostics);
21697+
const chain = map(diags, d => typeof d.messageText === "string" ? (d as DiagnosticMessageChain) : d.messageText);
21698+
const related = flatMap(diags, d => (d as Diagnostic).relatedInformation) as DiagnosticRelatedInformation[];
21699+
diagnostics.add(createDiagnosticForNodeFromMessageChain(node, chainDiagnosticMessages(chain, Diagnostics.No_overload_matches_this_call), related));
2170021700
}
2170121701
}
2170221702
else if (candidateForArgumentArityError) {

src/compiler/utilities.ts

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7170,36 +7170,6 @@ namespace ts {
71707170
return d1.relatedInformation ? Comparison.LessThan : Comparison.GreaterThan;
71717171
}
71727172

7173-
// function compareMessageText(t1: string | DiagnosticMessageChain[], t2: string | DiagnosticMessageChain[]): Comparison {
7174-
// if (typeof t1 === 'string' && typeof t2 === 'string') {
7175-
// return compareStringsCaseSensitive(t1, t2)
7176-
// }
7177-
// else if (Array.isArray(t1) && Array.isArray(t2)) {
7178-
// if (t1.length < t2.length) {
7179-
// return Comparison.LessThan;
7180-
// }
7181-
// else if (t1.length > t2.length) {
7182-
// return Comparison.GreaterThan;
7183-
// }
7184-
// else {
7185-
// for (let i = 0; i < t1.length; i++) {
7186-
// t1[i].messageText
7187-
// const res = cmps(t1[i], t2[i]);
7188-
// if (res) {
7189-
// return res;
7190-
// }
7191-
// }
7192-
// return Comparison.EqualTo;
7193-
// }
7194-
// }
7195-
// else if (typeof t1 === 'string') {
7196-
// return Comparison.LessThan;
7197-
// }
7198-
// else {
7199-
// return Comparison.GreaterThan;
7200-
// }
7201-
// }
7202-
72037173
function compareMessageText(t1: string | DiagnosticMessageChain, t2: string | DiagnosticMessageChain): Comparison {
72047174
if (typeof t1 === "string" && typeof t2 === "string") {
72057175
return compareStringsCaseSensitive(t1, t2);
@@ -7223,16 +7193,19 @@ namespace ts {
72237193
if (!t2.next) {
72247194
return Comparison.GreaterThan;
72257195
}
7226-
res = compareValues(t1.next.length, t2.next.length);
7227-
if (res) {
7228-
return res;
7229-
}
7230-
for (let i = 0; i < t1.next.length; i++) {
7196+
const len = Math.min(t1.next.length, t2.next.length);
7197+
for (let i = 0; i < len; i++) {
72317198
res = compareMessageText(t1.next[i], t2.next[i]);
72327199
if (res) {
72337200
return res;
72347201
}
72357202
}
7203+
if (t1.next.length < t2.next.length) {
7204+
return Comparison.LessThan;
7205+
}
7206+
else if (t1.next.length > t2.next.length) {
7207+
return Comparison.GreaterThan;
7208+
}
72367209
return Comparison.EqualTo;
72377210
}
72387211

tests/baselines/reference/functionOverloads40.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ tests/cases/compiler/functionOverloads40.ts(4,9): error TS2763: No overload matc
1616
!!! error TS2763: Type 'string' is not assignable to type 'number'.
1717
!!! error TS2763: Overload 2 of 2, '(bar: { a: boolean; }[]): number', gave the following error.
1818
!!! error TS2763: Type 'string' is not assignable to type 'boolean'.
19+
!!! related TS6500 tests/cases/compiler/functionOverloads40.ts:1:19: The expected type comes from property 'a' which is declared here on type '{ a: number; }'
20+
!!! related TS6500 tests/cases/compiler/functionOverloads40.ts:2:19: The expected type comes from property 'a' which is declared here on type '{ a: boolean; }'
1921

tests/baselines/reference/functionOverloads41.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ tests/cases/compiler/functionOverloads41.ts(4,9): error TS2763: No overload matc
1616
!!! error TS2763: Property 'a' is missing in type '{}' but required in type '{ a: number; }'.
1717
!!! error TS2763: Overload 2 of 2, '(bar: { a: boolean; }[]): number', gave the following error.
1818
!!! error TS2763: Property 'a' is missing in type '{}' but required in type '{ a: boolean; }'.
19+
!!! related TS2728 tests/cases/compiler/functionOverloads41.ts:1:19: 'a' is declared here.
20+
!!! related TS2728 tests/cases/compiler/functionOverloads41.ts:2:19: 'a' is declared here.
1921

tests/baselines/reference/overloadResolutionTest1.errors.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ tests/cases/compiler/overloadResolutionTest1.ts(24,9): error TS2763: No overload
2929
!!! error TS2763: Type 'string' is not assignable to type 'number'.
3030
!!! error TS2763: Overload 2 of 2, '(bar: { a: boolean; }[]): number', gave the following error.
3131
!!! error TS2763: Type 'string' is not assignable to type 'boolean'.
32+
!!! related TS6500 tests/cases/compiler/overloadResolutionTest1.ts:1:19: The expected type comes from property 'a' which is declared here on type '{ a: number; }'
33+
!!! related TS6500 tests/cases/compiler/overloadResolutionTest1.ts:2:19: The expected type comes from property 'a' which is declared here on type '{ a: boolean; }'
3234
var x1111 = foo([{a:null}]); // works - ambiguous call is resolved to be the first in the overload set so this returns a string
3335

3436

@@ -46,6 +48,8 @@ tests/cases/compiler/overloadResolutionTest1.ts(24,9): error TS2763: No overload
4648
!!! error TS2763: Type 'string' is not assignable to type 'number'.
4749
!!! error TS2763: Overload 2 of 2, '(bar: { a: boolean; }): number', gave the following error.
4850
!!! error TS2763: Type 'string' is not assignable to type 'boolean'.
51+
!!! related TS6500 tests/cases/compiler/overloadResolutionTest1.ts:12:20: The expected type comes from property 'a' which is declared here on type '{ a: number; }'
52+
!!! related TS6500 tests/cases/compiler/overloadResolutionTest1.ts:13:20: The expected type comes from property 'a' which is declared here on type '{ a: boolean; }'
4953

5054

5155
function foo4(bar:{a:number;}):number;
@@ -57,4 +61,6 @@ tests/cases/compiler/overloadResolutionTest1.ts(24,9): error TS2763: No overload
5761
!!! error TS2763: Overload 1 of 2, '(bar: { a: number; }): number', gave the following error.
5862
!!! error TS2763: Type 'true' is not assignable to type 'number'.
5963
!!! error TS2763: Overload 2 of 2, '(bar: { a: string; }): string', gave the following error.
60-
!!! error TS2763: Type 'true' is not assignable to type 'string'.
64+
!!! error TS2763: Type 'true' is not assignable to type 'string'.
65+
!!! related TS6500 tests/cases/compiler/overloadResolutionTest1.ts:21:20: The expected type comes from property 'a' which is declared here on type '{ a: number; }'
66+
!!! related TS6500 tests/cases/compiler/overloadResolutionTest1.ts:22:20: The expected type comes from property 'a' which is declared here on type '{ a: string; }'

tests/baselines/reference/overloadresolutionWithConstraintCheckingDeferred.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,6 @@ tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(19,14):
6868
!!! error TS2763: Argument of type '(x: D) => G<D>' is not assignable to parameter of type '(x: B) => any'.
6969
!!! error TS2763: Types of parameters 'x' and 'x' are incompatible.
7070
!!! error TS2763: Property 'q' is missing in type 'B' but required in type 'D'.
71+
!!! related TS2728 tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts:4:15: 'q' is declared here.
72+
!!! related TS2728 tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts:4:15: 'q' is declared here.
7173

tests/baselines/reference/overloadsWithProvisionalErrors.errors.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ tests/cases/compiler/overloadsWithProvisionalErrors.ts(8,17): error TS2304: Cann
2525
!!! error TS2763: Argument of type '(s: string) => {}' is not assignable to parameter of type 'string'.
2626
!!! error TS2763: Overload 2 of 2, '(lambda: (s: string) => { a: number; b: number; }): string', gave the following error.
2727
!!! error TS2763: Type '{}' is missing the following properties from type '{ a: number; b: number; }': a, b
28+
!!! related TS6502 tests/cases/compiler/overloadsWithProvisionalErrors.ts:3:14: The expected type comes from the return type of this signature.
2829
func(s => ({ a: blah, b: 3 })); // Only error inside the function, but not outside (since it would be applicable if not for the provisional error)
2930
~~~~
3031
!!! error TS2304: Cannot find name 'blah'.
@@ -35,5 +36,7 @@ tests/cases/compiler/overloadsWithProvisionalErrors.ts(8,17): error TS2304: Cann
3536
!!! error TS2763: Argument of type '(s: string) => { a: any; }' is not assignable to parameter of type 'string'.
3637
!!! error TS2763: Overload 2 of 2, '(lambda: (s: string) => { a: number; b: number; }): string', gave the following error.
3738
!!! error TS2763: Property 'b' is missing in type '{ a: any; }' but required in type '{ a: number; b: number; }'.
39+
!!! related TS2728 tests/cases/compiler/overloadsWithProvisionalErrors.ts:3:42: 'b' is declared here.
40+
!!! related TS6502 tests/cases/compiler/overloadsWithProvisionalErrors.ts:3:14: The expected type comes from the return type of this signature.
3841
~~~~
3942
!!! error TS2304: Cannot find name 'blah'.

tests/baselines/reference/promiseTypeInference.errors.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,7 @@ tests/cases/compiler/promiseTypeInference.ts(10,11): error TS2763: No overload m
3434
!!! error TS2763: Types of parameters 'success' and 'onfulfilled' are incompatible.
3535
!!! error TS2763: Type 'TResult1 | PromiseLike<TResult1>' is not assignable to type 'IPromise<TResult1 | TResult2>'.
3636
!!! error TS2763: Type 'TResult1' is not assignable to type 'IPromise<TResult1 | TResult2>'.
37+
!!! related TS2728 /.ts/lib.es5.d.ts:1413:5: 'catch' is declared here.
38+
!!! related TS6502 tests/cases/compiler/promiseTypeInference.ts:2:23: The expected type comes from the return type of this signature.
39+
!!! related TS6502 /.ts/lib.es5.d.ts:1406:57: The expected type comes from the return type of this signature.
3740

tests/baselines/reference/tsxStatelessFunctionComponentOverload4.errors.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ tests/cases/conformance/jsx/file.tsx(36,12): error TS2763: No overload matches t
105105
!!! error TS2763: Property 'yy' does not exist on type 'IntrinsicAttributes'.
106106
!!! error TS2763: Overload 2 of 2, '(l: { yy: number; yy1: string; }): Element', gave the following error.
107107
!!! error TS2763: Property 'yy1' is missing in type '{ yy: number; }' but required in type '{ yy: number; yy1: string; }'.
108+
!!! related TS2728 tests/cases/conformance/jsx/file.tsx:3:43: 'yy1' is declared here.
108109
const c2 = <OneThing {...obj} yy1 />; // type incompatible;
109110
~~~~~~~~~~~~~~~~~~~~~~~~~
110111
!!! error TS2763: No overload matches this call.
@@ -113,6 +114,7 @@ tests/cases/conformance/jsx/file.tsx(36,12): error TS2763: No overload matches t
113114
!!! error TS2763: Property 'yy1' does not exist on type 'IntrinsicAttributes'.
114115
!!! error TS2763: Overload 2 of 2, '(l: { yy: number; yy1: string; }): Element', gave the following error.
115116
!!! error TS2763: Type 'true' is not assignable to type 'string'.
117+
!!! related TS6500 tests/cases/conformance/jsx/file.tsx:3:43: The expected type comes from property 'yy1' which is declared here on type 'IntrinsicAttributes & { yy: number; yy1: string; }'
116118
const c3 = <OneThing {...obj} {...{extra: "extra attr"}} />; // This is OK becuase all attribute are spread
117119
const c4 = <OneThing {...obj} y1={10000} />; // extra property;
118120
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -146,6 +148,8 @@ tests/cases/conformance/jsx/file.tsx(36,12): error TS2763: No overload matches t
146148
!!! error TS2763: Type 'true' is not assignable to type 'string'.
147149
!!! error TS2763: Overload 2 of 2, '(n: { yy: string; direction?: number; }): Element', gave the following error.
148150
!!! error TS2763: Property 'yy' is missing in type '{ extra-data: true; }' but required in type '{ yy: string; direction?: number; }'.
151+
!!! related TS6500 tests/cases/conformance/jsx/file.tsx:21:38: The expected type comes from property 'extra-data' which is declared here on type 'IntrinsicAttributes & { "extra-data": string; }'
152+
!!! related TS2728 tests/cases/conformance/jsx/file.tsx:22:38: 'yy' is declared here.
149153
const d2 = <TestingOneThing yy="hello" direction="left" />
150154
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
151155
!!! error TS2763: No overload matches this call.
@@ -154,6 +158,7 @@ tests/cases/conformance/jsx/file.tsx(36,12): error TS2763: No overload matches t
154158
!!! error TS2763: Property 'yy' does not exist on type 'IntrinsicAttributes & { "extra-data": string; }'.
155159
!!! error TS2763: Overload 2 of 2, '(n: { yy: string; direction?: number; }): Element', gave the following error.
156160
!!! error TS2763: Type 'string' is not assignable to type 'number'.
161+
!!! related TS6500 tests/cases/conformance/jsx/file.tsx:22:50: The expected type comes from property 'direction' which is declared here on type 'IntrinsicAttributes & { yy: string; direction?: number; }'
157162

158163
declare function TestingOptional(a: {y1?: string, y2?: number}): JSX.Element;
159164
declare function TestingOptional(a: {y1?: string, y2?: number, children: JSX.Element}): JSX.Element;
@@ -169,6 +174,9 @@ tests/cases/conformance/jsx/file.tsx(36,12): error TS2763: No overload matches t
169174
!!! error TS2763: Type 'true' is not assignable to type 'string'.
170175
!!! error TS2763: Overload 3 of 3, '(a: { y1: boolean; y2?: number; y3: boolean; }): Element', gave the following error.
171176
!!! error TS2763: Type 'string' is not assignable to type 'boolean'.
177+
!!! related TS6500 tests/cases/conformance/jsx/file.tsx:28:38: The expected type comes from property 'y1' which is declared here on type 'IntrinsicAttributes & { y1?: string; y2?: number; }'
178+
!!! related TS6500 tests/cases/conformance/jsx/file.tsx:29:38: The expected type comes from property 'y1' which is declared here on type 'IntrinsicAttributes & { y1?: string; y2?: number; children: Element; }'
179+
!!! related TS6500 tests/cases/conformance/jsx/file.tsx:30:64: The expected type comes from property 'y3' which is declared here on type 'IntrinsicAttributes & { y1: boolean; y2?: number; y3: boolean; }'
172180
const e2 = <TestingOptional y1="hello" y2={1000} y3 />
173181
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
174182
!!! error TS2763: No overload matches this call.
@@ -180,6 +188,7 @@ tests/cases/conformance/jsx/file.tsx(36,12): error TS2763: No overload matches t
180188
!!! error TS2763: Property 'y3' does not exist on type 'IntrinsicAttributes & { y1?: string; y2?: number; children: Element; }'.
181189
!!! error TS2763: Overload 3 of 3, '(a: { y1: boolean; y2?: number; y3: boolean; }): Element', gave the following error.
182190
!!! error TS2763: Type 'string' is not assignable to type 'boolean'.
191+
!!! related TS6500 tests/cases/conformance/jsx/file.tsx:30:38: The expected type comes from property 'y1' which is declared here on type 'IntrinsicAttributes & { y1: boolean; y2?: number; y3: boolean; }'
183192
const e3 = <TestingOptional y1="hello" y2={1000} children="hi" />
184193
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
185194
!!! error TS2763: No overload matches this call.
@@ -190,6 +199,8 @@ tests/cases/conformance/jsx/file.tsx(36,12): error TS2763: No overload matches t
190199
!!! error TS2763: Type 'string' is not assignable to type 'Element'.
191200
!!! error TS2763: Overload 3 of 3, '(a: { y1: boolean; y2?: number; y3: boolean; }): Element', gave the following error.
192201
!!! error TS2763: Type 'string' is not assignable to type 'boolean'.
202+
!!! related TS6500 tests/cases/conformance/jsx/file.tsx:29:64: The expected type comes from property 'children' which is declared here on type 'IntrinsicAttributes & { y1?: string; y2?: number; children: Element; }'
203+
!!! related TS6500 tests/cases/conformance/jsx/file.tsx:30:38: The expected type comes from property 'y1' which is declared here on type 'IntrinsicAttributes & { y1: boolean; y2?: number; y3: boolean; }'
193204
const e4 = <TestingOptional y1="hello" y2={1000}>Hi</TestingOptional>
194205
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
195206
!!! error TS2763: No overload matches this call.
@@ -200,4 +211,6 @@ tests/cases/conformance/jsx/file.tsx(36,12): error TS2763: No overload matches t
200211
!!! error TS2763: 'TestingOptional' components don't accept text as child elements. Text in JSX has the type 'string', but the expected type of 'children' is 'Element'.
201212
!!! error TS2763: Overload 3 of 3, '(a: { y1: boolean; y2?: number; y3: boolean; }): Element', gave the following error.
202213
!!! error TS2763: Type 'string' is not assignable to type 'boolean'.
214+
!!! related TS6500 tests/cases/conformance/jsx/file.tsx:29:64: The expected type comes from property 'children' which is declared here on type 'IntrinsicAttributes & { y1?: string; y2?: number; children: Element; }'
215+
!!! related TS6500 tests/cases/conformance/jsx/file.tsx:30:38: The expected type comes from property 'y1' which is declared here on type 'IntrinsicAttributes & { y1: boolean; y2?: number; y3: boolean; }'
203216

0 commit comments

Comments
 (0)