Skip to content

Commit 26caa37

Browse files
authored
Introduce flattened error reporting for properties, call signatures, and construct signatures (#33473)
* Introduce flattened error reporting for properties, call signatures, and construct signatures * Update message, specialize output for argument-less signatures * Skip leading signature incompatability flattening * Add return type specialized message
1 parent 6c2ae12 commit 26caa37

File tree

62 files changed

+1023
-735
lines changed

Some content is hidden

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

62 files changed

+1023
-735
lines changed

scripts/processDiagnosticMessages.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ interface DiagnosticDetails {
66
code: number;
77
reportsUnnecessary?: {};
88
isEarly?: boolean;
9+
elidedInCompatabilityPyramid?: boolean;
910
}
1011

1112
type InputDiagnosticMessageTable = Map<string, DiagnosticDetails>;
@@ -63,14 +64,15 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, inputFil
6364
"// generated from '" + inputFilePathRel + "' by '" + thisFilePathRel.replace(/\\/g, "/") + "'\r\n" +
6465
"/* @internal */\r\n" +
6566
"namespace ts {\r\n" +
66-
" function diag(code: number, category: DiagnosticCategory, key: string, message: string, reportsUnnecessary?: {}): DiagnosticMessage {\r\n" +
67-
" return { code, category, key, message, reportsUnnecessary };\r\n" +
67+
" function diag(code: number, category: DiagnosticCategory, key: string, message: string, reportsUnnecessary?: {}, elidedInCompatabilityPyramid?: boolean): DiagnosticMessage {\r\n" +
68+
" return { code, category, key, message, reportsUnnecessary, elidedInCompatabilityPyramid };\r\n" +
6869
" }\r\n" +
6970
" export const Diagnostics = {\r\n";
70-
messageTable.forEach(({ code, category, reportsUnnecessary }, name) => {
71+
messageTable.forEach(({ code, category, reportsUnnecessary, elidedInCompatabilityPyramid }, name) => {
7172
const propName = convertPropertyName(name);
7273
const argReportsUnnecessary = reportsUnnecessary ? `, /*reportsUnnecessary*/ ${reportsUnnecessary}` : "";
73-
result += ` ${propName}: diag(${code}, DiagnosticCategory.${category}, "${createKey(propName, code)}", ${JSON.stringify(name)}${argReportsUnnecessary}),\r\n`;
74+
const argElidedInCompatabilityPyramid = elidedInCompatabilityPyramid ? `${!reportsUnnecessary ? ", /*reportsUnnecessary*/ undefined" : ""}, /*elidedInCompatabilityPyramid*/ ${elidedInCompatabilityPyramid}` : "";
75+
result += ` ${propName}: diag(${code}, DiagnosticCategory.${category}, "${createKey(propName, code)}", ${JSON.stringify(name)}${argReportsUnnecessary}${argElidedInCompatabilityPyramid}),\r\n`;
7476
});
7577

7678
result += " };\r\n}";

src/compiler/checker.ts

+190-36
Large diffs are not rendered by default.

src/compiler/diagnosticMessages.json

+29
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,35 @@
10401040
"code": 1357
10411041
},
10421042

1043+
"The types of '{0}' are incompatible between these types.": {
1044+
"category": "Error",
1045+
"code": 2200
1046+
},
1047+
"The types returned by '{0}' are incompatible between these types.": {
1048+
"category": "Error",
1049+
"code": 2201
1050+
},
1051+
"Call signature return types '{0}' and '{1}' are incompatible.": {
1052+
"category": "Error",
1053+
"code": 2202,
1054+
"elidedInCompatabilityPyramid": true
1055+
},
1056+
"Construct signature return types '{0}' and '{1}' are incompatible.": {
1057+
"category": "Error",
1058+
"code": 2203,
1059+
"elidedInCompatabilityPyramid": true
1060+
},
1061+
"Call signatures with no arguments have incompatible return types '{0}' and '{1}'.": {
1062+
"category": "Error",
1063+
"code": 2204,
1064+
"elidedInCompatabilityPyramid": true
1065+
},
1066+
"Construct signatures with no arguments have incompatible return types '{0}' and '{1}'.": {
1067+
"category": "Error",
1068+
"code": 2205,
1069+
"elidedInCompatabilityPyramid": true
1070+
},
1071+
10431072
"Duplicate identifier '{0}'.": {
10441073
"category": "Error",
10451074
"code": 2300

src/compiler/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4631,6 +4631,8 @@ namespace ts {
46314631
code: number;
46324632
message: string;
46334633
reportsUnnecessary?: {};
4634+
/* @internal */
4635+
elidedInCompatabilityPyramid?: boolean;
46344636
}
46354637

46364638
/**

tests/baselines/reference/arrayLiterals3.errors.txt

+6-8
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(17,5): error
88
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(32,5): error TS2739: Type '(number[] | string[])[]' is missing the following properties from type 'tup': 0, 1
99
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(33,5): error TS2739: Type 'number[]' is missing the following properties from type '[number, number, number]': 0, 1, 2
1010
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'.
11-
Types of property 'pop' are incompatible.
12-
Type '() => string | number' is not assignable to type '() => Number'.
13-
Type 'string | number' is not assignable to type 'Number'.
14-
Type 'string' is not assignable to type 'Number'.
11+
The types returned by 'pop()' are incompatible between these types.
12+
Type 'string | number' is not assignable to type 'Number'.
13+
Type 'string' is not assignable to type 'Number'.
1514

1615

1716
==== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts (8 errors) ====
@@ -67,8 +66,7 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error
6766
var c2: myArray = [...temp1, ...temp]; // Error cannot assign (number|string)[] to number[]
6867
~~
6968
!!! error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'.
70-
!!! error TS2322: Types of property 'pop' are incompatible.
71-
!!! error TS2322: Type '() => string | number' is not assignable to type '() => Number'.
72-
!!! error TS2322: Type 'string | number' is not assignable to type 'Number'.
73-
!!! error TS2322: Type 'string' is not assignable to type 'Number'.
69+
!!! error TS2322: The types returned by 'pop()' are incompatible between these types.
70+
!!! error TS2322: Type 'string | number' is not assignable to type 'Number'.
71+
!!! error TS2322: Type 'string' is not assignable to type 'Number'.
7472

tests/baselines/reference/arrayOfSubtypeIsAssignableToReadonlyArray.errors.txt

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts(13,1): error TS2322: Type 'A[]' is not assignable to type 'readonly B[]'.
22
Property 'b' is missing in type 'A' but required in type 'B'.
33
tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts(18,1): error TS2322: Type 'C<A>' is not assignable to type 'readonly B[]'.
4-
Types of property 'concat' are incompatible.
5-
Type '{ (...items: ConcatArray<A>[]): A[]; (...items: (A | ConcatArray<A>)[]): A[]; }' is not assignable to type '{ (...items: ConcatArray<B>[]): B[]; (...items: (B | ConcatArray<B>)[]): B[]; }'.
6-
Type 'A[]' is not assignable to type 'B[]'.
7-
Type 'A' is not assignable to type 'B'.
4+
The types returned by 'concat(...)' are incompatible between these types.
5+
Type 'A[]' is not assignable to type 'B[]'.
6+
Type 'A' is not assignable to type 'B'.
87

98

109
==== tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts (2 errors) ====
@@ -32,8 +31,7 @@ tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts(18,1): error T
3231
rrb = cra; // error: 'A' is not assignable to 'B'
3332
~~~
3433
!!! error TS2322: Type 'C<A>' is not assignable to type 'readonly B[]'.
35-
!!! error TS2322: Types of property 'concat' are incompatible.
36-
!!! error TS2322: Type '{ (...items: ConcatArray<A>[]): A[]; (...items: (A | ConcatArray<A>)[]): A[]; }' is not assignable to type '{ (...items: ConcatArray<B>[]): B[]; (...items: (B | ConcatArray<B>)[]): B[]; }'.
37-
!!! error TS2322: Type 'A[]' is not assignable to type 'B[]'.
38-
!!! error TS2322: Type 'A' is not assignable to type 'B'.
34+
!!! error TS2322: The types returned by 'concat(...)' are incompatible between these types.
35+
!!! error TS2322: Type 'A[]' is not assignable to type 'B[]'.
36+
!!! error TS2322: Type 'A' is not assignable to type 'B'.
3937

tests/baselines/reference/assignFromBooleanInterface2.errors.txt

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
tests/cases/conformance/types/primitives/boolean/assignFromBooleanInterface2.ts(14,1): error TS2322: Type 'NotBoolean' is not assignable to type 'Boolean'.
2-
Types of property 'valueOf' are incompatible.
3-
Type '() => Object' is not assignable to type '() => boolean'.
4-
Type 'Object' is not assignable to type 'boolean'.
2+
The types returned by 'valueOf()' are incompatible between these types.
3+
Type 'Object' is not assignable to type 'boolean'.
54
tests/cases/conformance/types/primitives/boolean/assignFromBooleanInterface2.ts(19,1): error TS2322: Type 'Boolean' is not assignable to type 'boolean'.
65
'boolean' is a primitive, but 'Boolean' is a wrapper object. Prefer using 'boolean' when possible.
76
tests/cases/conformance/types/primitives/boolean/assignFromBooleanInterface2.ts(20,1): error TS2322: Type 'NotBoolean' is not assignable to type 'boolean'.
@@ -24,9 +23,8 @@ tests/cases/conformance/types/primitives/boolean/assignFromBooleanInterface2.ts(
2423
a = b;
2524
~
2625
!!! error TS2322: Type 'NotBoolean' is not assignable to type 'Boolean'.
27-
!!! error TS2322: Types of property 'valueOf' are incompatible.
28-
!!! error TS2322: Type '() => Object' is not assignable to type '() => boolean'.
29-
!!! error TS2322: Type 'Object' is not assignable to type 'boolean'.
26+
!!! error TS2322: The types returned by 'valueOf()' are incompatible between these types.
27+
!!! error TS2322: Type 'Object' is not assignable to type 'boolean'.
3028

3129
b = a;
3230
b = x;

tests/baselines/reference/asyncFunctionDeclaration15_es5.errors.txt

+6-8
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration1
55
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(8,23): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.
66
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(9,23): error TS1055: Type 'PromiseLike' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value.
77
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(10,23): error TS1055: Type 'typeof Thenable' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value.
8-
Type 'Thenable' is not assignable to type 'PromiseLike<T>'.
9-
Types of property 'then' are incompatible.
10-
Type '() => void' is not assignable to type '<TResult1 = T, TResult2 = never>(onfulfilled?: (value: T) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => PromiseLike<TResult1 | TResult2>'.
11-
Type 'void' is not assignable to type 'PromiseLike<TResult1 | TResult2>'.
8+
Construct signature return types 'Thenable' and 'PromiseLike<T>' are incompatible.
9+
The types returned by 'then(...)' are incompatible between these types.
10+
Type 'void' is not assignable to type 'PromiseLike<TResult1 | TResult2>'.
1211
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(17,16): error TS1058: The return type of an async function must either be a valid promise or must not contain a callable 'then' member.
1312
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(23,25): error TS1320: Type of 'await' operand must either be a valid promise or must not contain a callable 'then' member.
1413

@@ -38,10 +37,9 @@ tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration1
3837
async function fn6(): Thenable { } // error
3938
~~~~~~~~
4039
!!! error TS1055: Type 'typeof Thenable' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value.
41-
!!! error TS1055: Type 'Thenable' is not assignable to type 'PromiseLike<T>'.
42-
!!! error TS1055: Types of property 'then' are incompatible.
43-
!!! error TS1055: Type '() => void' is not assignable to type '<TResult1 = T, TResult2 = never>(onfulfilled?: (value: T) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => PromiseLike<TResult1 | TResult2>'.
44-
!!! error TS1055: Type 'void' is not assignable to type 'PromiseLike<TResult1 | TResult2>'.
40+
!!! error TS1055: Construct signature return types 'Thenable' and 'PromiseLike<T>' are incompatible.
41+
!!! error TS1055: The types returned by 'then(...)' are incompatible between these types.
42+
!!! error TS1055: Type 'void' is not assignable to type 'PromiseLike<TResult1 | TResult2>'.
4543
async function fn7() { return; } // valid: Promise<void>
4644
async function fn8() { return 1; } // valid: Promise<number>
4745
async function fn9() { return null; } // valid: Promise<any>

tests/baselines/reference/bigintWithLib.errors.txt

+10-18
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@ tests/cases/compiler/bigintWithLib.ts(16,33): error TS2769: No overload matches
44
Argument of type 'number[]' is not assignable to parameter of type 'number'.
55
Overload 2 of 3, '(array: Iterable<bigint>): BigInt64Array', gave the following error.
66
Argument of type 'number[]' is not assignable to parameter of type 'Iterable<bigint>'.
7-
Types of property '[Symbol.iterator]' are incompatible.
8-
Type '() => IterableIterator<number>' is not assignable to type '() => Iterator<bigint, any, undefined>'.
9-
Type 'IterableIterator<number>' is not assignable to type 'Iterator<bigint, any, undefined>'.
10-
Types of property 'next' are incompatible.
11-
Type '(...args: [] | [undefined]) => IteratorResult<number, any>' is not assignable to type '(...args: [] | [undefined]) => IteratorResult<bigint, any>'.
12-
Type 'IteratorResult<number, any>' is not assignable to type 'IteratorResult<bigint, any>'.
13-
Type 'IteratorYieldResult<number>' is not assignable to type 'IteratorResult<bigint, any>'.
14-
Type 'IteratorYieldResult<number>' is not assignable to type 'IteratorYieldResult<bigint>'.
15-
Type 'number' is not assignable to type 'bigint'.
7+
The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types.
8+
Type 'IteratorResult<number, any>' is not assignable to type 'IteratorResult<bigint, any>'.
9+
Type 'IteratorYieldResult<number>' is not assignable to type 'IteratorResult<bigint, any>'.
10+
Type 'IteratorYieldResult<number>' is not assignable to type 'IteratorYieldResult<bigint>'.
11+
Type 'number' is not assignable to type 'bigint'.
1612
Overload 3 of 3, '(buffer: ArrayBuffer | SharedArrayBuffer, byteOffset?: number, length?: number): BigInt64Array', gave the following error.
1713
Argument of type 'number[]' is not assignable to parameter of type 'ArrayBuffer | SharedArrayBuffer'.
1814
Type 'number[]' is missing the following properties from type 'SharedArrayBuffer': byteLength, [Symbol.species], [Symbol.toStringTag]
@@ -55,15 +51,11 @@ tests/cases/compiler/bigintWithLib.ts(43,26): error TS2345: Argument of type '12
5551
!!! error TS2769: Argument of type 'number[]' is not assignable to parameter of type 'number'.
5652
!!! error TS2769: Overload 2 of 3, '(array: Iterable<bigint>): BigInt64Array', gave the following error.
5753
!!! error TS2769: Argument of type 'number[]' is not assignable to parameter of type 'Iterable<bigint>'.
58-
!!! error TS2769: Types of property '[Symbol.iterator]' are incompatible.
59-
!!! error TS2769: Type '() => IterableIterator<number>' is not assignable to type '() => Iterator<bigint, any, undefined>'.
60-
!!! error TS2769: Type 'IterableIterator<number>' is not assignable to type 'Iterator<bigint, any, undefined>'.
61-
!!! error TS2769: Types of property 'next' are incompatible.
62-
!!! error TS2769: Type '(...args: [] | [undefined]) => IteratorResult<number, any>' is not assignable to type '(...args: [] | [undefined]) => IteratorResult<bigint, any>'.
63-
!!! error TS2769: Type 'IteratorResult<number, any>' is not assignable to type 'IteratorResult<bigint, any>'.
64-
!!! error TS2769: Type 'IteratorYieldResult<number>' is not assignable to type 'IteratorResult<bigint, any>'.
65-
!!! error TS2769: Type 'IteratorYieldResult<number>' is not assignable to type 'IteratorYieldResult<bigint>'.
66-
!!! error TS2769: Type 'number' is not assignable to type 'bigint'.
54+
!!! error TS2769: The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types.
55+
!!! error TS2769: Type 'IteratorResult<number, any>' is not assignable to type 'IteratorResult<bigint, any>'.
56+
!!! error TS2769: Type 'IteratorYieldResult<number>' is not assignable to type 'IteratorResult<bigint, any>'.
57+
!!! error TS2769: Type 'IteratorYieldResult<number>' is not assignable to type 'IteratorYieldResult<bigint>'.
58+
!!! error TS2769: Type 'number' is not assignable to type 'bigint'.
6759
!!! error TS2769: Overload 3 of 3, '(buffer: ArrayBuffer | SharedArrayBuffer, byteOffset?: number, length?: number): BigInt64Array', gave the following error.
6860
!!! error TS2769: Argument of type 'number[]' is not assignable to parameter of type 'ArrayBuffer | SharedArrayBuffer'.
6961
!!! error TS2769: Type 'number[]' is missing the following properties from type 'SharedArrayBuffer': byteLength, [Symbol.species], [Symbol.toStringTag]

tests/baselines/reference/booleanAssignment.errors.txt

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
tests/cases/compiler/booleanAssignment.ts(2,1): error TS2322: Type '1' is not assignable to type 'Boolean'.
22
tests/cases/compiler/booleanAssignment.ts(3,1): error TS2322: Type '"a"' is not assignable to type 'Boolean'.
33
tests/cases/compiler/booleanAssignment.ts(4,1): error TS2322: Type '{}' is not assignable to type 'Boolean'.
4-
Types of property 'valueOf' are incompatible.
5-
Type '() => Object' is not assignable to type '() => boolean'.
6-
Type 'Object' is not assignable to type 'boolean'.
4+
The types returned by 'valueOf()' are incompatible between these types.
5+
Type 'Object' is not assignable to type 'boolean'.
76

87

98
==== tests/cases/compiler/booleanAssignment.ts (3 errors) ====
@@ -17,9 +16,8 @@ tests/cases/compiler/booleanAssignment.ts(4,1): error TS2322: Type '{}' is not a
1716
b = {}; // Error
1817
~
1918
!!! error TS2322: Type '{}' is not assignable to type 'Boolean'.
20-
!!! error TS2322: Types of property 'valueOf' are incompatible.
21-
!!! error TS2322: Type '() => Object' is not assignable to type '() => boolean'.
22-
!!! error TS2322: Type 'Object' is not assignable to type 'boolean'.
19+
!!! error TS2322: The types returned by 'valueOf()' are incompatible between these types.
20+
!!! error TS2322: Type 'Object' is not assignable to type 'boolean'.
2321

2422
var o = {};
2523
o = b; // OK

0 commit comments

Comments
 (0)