Skip to content

Commit 8d3038a

Browse files
committed
Add return type specialized message
1 parent f5dc527 commit 8d3038a

34 files changed

+139
-131
lines changed

src/compiler/checker.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -12827,7 +12827,11 @@ namespace ts {
1282712827
}
1282812828
}
1282912829
if (path) {
12830-
reportError(Diagnostics.The_types_of_0_are_incompatible_between_these_types, path);
12830+
reportError(path[path.length - 1] === ")"
12831+
? Diagnostics.The_types_returned_by_0_are_incompatible_between_these_types
12832+
: Diagnostics.The_types_of_0_are_incompatible_between_these_types,
12833+
path
12834+
);
1283112835
}
1283212836
else {
1283312837
// Remove the innermost secondary error as it will duplicate the error already reported by `reportRelationError` on entry

src/compiler/diagnosticMessages.json

+8-4
Original file line numberDiff line numberDiff line change
@@ -1044,24 +1044,28 @@
10441044
"category": "Error",
10451045
"code": 2200
10461046
},
1047+
"The types returned by '{0}' are incompatible between these types.": {
1048+
"category": "Error",
1049+
"code": 2201
1050+
},
10471051
"Call signature return types '{0}' and '{1}' are incompatible.": {
10481052
"category": "Error",
1049-
"code": 2201,
1053+
"code": 2202,
10501054
"elidedInCompatabilityPyramid": true
10511055
},
10521056
"Construct signature return types '{0}' and '{1}' are incompatible.": {
10531057
"category": "Error",
1054-
"code": 2202,
1058+
"code": 2203,
10551059
"elidedInCompatabilityPyramid": true
10561060
},
10571061
"Call signatures with no arguments have incompatible return types '{0}' and '{1}'.": {
10581062
"category": "Error",
1059-
"code": 2203,
1063+
"code": 2204,
10601064
"elidedInCompatabilityPyramid": true
10611065
},
10621066
"Construct signatures with no arguments have incompatible return types '{0}' and '{1}'.": {
10631067
"category": "Error",
1064-
"code": 2204,
1068+
"code": 2205,
10651069
"elidedInCompatabilityPyramid": true
10661070
},
10671071

tests/baselines/reference/arrayLiterals3.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ 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-
The types of 'pop()' are incompatible between these types.
11+
The types returned by 'pop()' are incompatible between these types.
1212
Type 'string | number' is not assignable to type 'Number'.
1313
Type 'string' is not assignable to type 'Number'.
1414

@@ -66,7 +66,7 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error
6666
var c2: myArray = [...temp1, ...temp]; // Error cannot assign (number|string)[] to number[]
6767
~~
6868
!!! error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'.
69-
!!! error TS2322: The types of 'pop()' are incompatible between these types.
69+
!!! error TS2322: The types returned by 'pop()' are incompatible between these types.
7070
!!! error TS2322: Type 'string | number' is not assignable to type 'Number'.
7171
!!! error TS2322: Type 'string' is not assignable to type 'Number'.
7272

tests/baselines/reference/arrayOfSubtypeIsAssignableToReadonlyArray.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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-
The types of 'concat(...)' are incompatible between these types.
4+
The types returned by 'concat(...)' are incompatible between these types.
55
Type 'A[]' is not assignable to type 'B[]'.
66
Type 'A' is not assignable to type 'B'.
77

@@ -31,7 +31,7 @@ tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts(18,1): error T
3131
rrb = cra; // error: 'A' is not assignable to 'B'
3232
~~~
3333
!!! error TS2322: Type 'C<A>' is not assignable to type 'readonly B[]'.
34-
!!! error TS2322: The types of 'concat(...)' are incompatible between these types.
34+
!!! error TS2322: The types returned by 'concat(...)' are incompatible between these types.
3535
!!! error TS2322: Type 'A[]' is not assignable to type 'B[]'.
3636
!!! error TS2322: Type 'A' is not assignable to type 'B'.
3737

tests/baselines/reference/assignFromBooleanInterface2.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tests/cases/conformance/types/primitives/boolean/assignFromBooleanInterface2.ts(14,1): error TS2322: Type 'NotBoolean' is not assignable to type 'Boolean'.
2-
The types of 'valueOf()' are incompatible between these types.
2+
The types returned by 'valueOf()' are incompatible between these types.
33
Type 'Object' is not assignable to type 'boolean'.
44
tests/cases/conformance/types/primitives/boolean/assignFromBooleanInterface2.ts(19,1): error TS2322: Type 'Boolean' is not assignable to type 'boolean'.
55
'boolean' is a primitive, but 'Boolean' is a wrapper object. Prefer using 'boolean' when possible.
@@ -23,7 +23,7 @@ tests/cases/conformance/types/primitives/boolean/assignFromBooleanInterface2.ts(
2323
a = b;
2424
~
2525
!!! error TS2322: Type 'NotBoolean' is not assignable to type 'Boolean'.
26-
!!! error TS2322: The types of 'valueOf()' are incompatible between these types.
26+
!!! error TS2322: The types returned by 'valueOf()' are incompatible between these types.
2727
!!! error TS2322: Type 'Object' is not assignable to type 'boolean'.
2828

2929
b = a;

tests/baselines/reference/asyncFunctionDeclaration15_es5.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration1
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.
88
Construct signature return types 'Thenable' and 'PromiseLike<T>' are incompatible.
9-
The types of 'then(...)' are incompatible between these types.
9+
The types returned by 'then(...)' are incompatible between these types.
1010
Type 'void' is not assignable to type 'PromiseLike<TResult1 | TResult2>'.
1111
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.
1212
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.
@@ -38,7 +38,7 @@ tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration1
3838
~~~~~~~~
3939
!!! 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.
4040
!!! error TS1055: Construct signature return types 'Thenable' and 'PromiseLike<T>' are incompatible.
41-
!!! error TS1055: The types of 'then(...)' are incompatible between these types.
41+
!!! error TS1055: The types returned by 'then(...)' are incompatible between these types.
4242
!!! error TS1055: Type 'void' is not assignable to type 'PromiseLike<TResult1 | TResult2>'.
4343
async function fn7() { return; } // valid: Promise<void>
4444
async function fn8() { return 1; } // valid: Promise<number>

tests/baselines/reference/bigintWithLib.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ 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-
The types of '[Symbol.iterator]().next(...)' are incompatible between these types.
7+
The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types.
88
Type 'IteratorResult<number, any>' is not assignable to type 'IteratorResult<bigint, any>'.
99
Type 'IteratorYieldResult<number>' is not assignable to type 'IteratorResult<bigint, any>'.
1010
Type 'IteratorYieldResult<number>' is not assignable to type 'IteratorYieldResult<bigint>'.
@@ -51,7 +51,7 @@ tests/cases/compiler/bigintWithLib.ts(43,26): error TS2345: Argument of type '12
5151
!!! error TS2769: Argument of type 'number[]' is not assignable to parameter of type 'number'.
5252
!!! error TS2769: Overload 2 of 3, '(array: Iterable<bigint>): BigInt64Array', gave the following error.
5353
!!! error TS2769: Argument of type 'number[]' is not assignable to parameter of type 'Iterable<bigint>'.
54-
!!! error TS2769: The types of '[Symbol.iterator]().next(...)' are incompatible between these types.
54+
!!! error TS2769: The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types.
5555
!!! error TS2769: Type 'IteratorResult<number, any>' is not assignable to type 'IteratorResult<bigint, any>'.
5656
!!! error TS2769: Type 'IteratorYieldResult<number>' is not assignable to type 'IteratorResult<bigint, any>'.
5757
!!! error TS2769: Type 'IteratorYieldResult<number>' is not assignable to type 'IteratorYieldResult<bigint>'.

tests/baselines/reference/booleanAssignment.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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-
The types of 'valueOf()' are incompatible between these types.
4+
The types returned by 'valueOf()' are incompatible between these types.
55
Type 'Object' is not assignable to type 'boolean'.
66

77

@@ -16,7 +16,7 @@ tests/cases/compiler/booleanAssignment.ts(4,1): error TS2322: Type '{}' is not a
1616
b = {}; // Error
1717
~
1818
!!! error TS2322: Type '{}' is not assignable to type 'Boolean'.
19-
!!! error TS2322: The types of 'valueOf()' are incompatible between these types.
19+
!!! error TS2322: The types returned by 'valueOf()' are incompatible between these types.
2020
!!! error TS2322: Type 'Object' is not assignable to type 'boolean'.
2121

2222
var o = {};

tests/baselines/reference/callSignatureAssignabilityInInheritance.errors.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance.ts(57,15): error TS2430: Interface 'I2' incorrectly extends interface 'Base2'.
2-
The types of 'a(...)' are incompatible between these types.
2+
The types returned by 'a(...)' are incompatible between these types.
33
Type 'string' is not assignable to type 'number'.
44
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance.ts(63,15): error TS2430: Interface 'I3' incorrectly extends interface 'Base2'.
5-
The types of 'a2(...)' are incompatible between these types.
5+
The types returned by 'a2(...)' are incompatible between these types.
66
Type 'string' is not assignable to type 'T'.
77
'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
88

@@ -67,7 +67,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSign
6767
interface I2 extends Base2 {
6868
~~
6969
!!! error TS2430: Interface 'I2' incorrectly extends interface 'Base2'.
70-
!!! error TS2430: The types of 'a(...)' are incompatible between these types.
70+
!!! error TS2430: The types returned by 'a(...)' are incompatible between these types.
7171
!!! error TS2430: Type 'string' is not assignable to type 'number'.
7272
// N's
7373
a: (x: number) => string; // error because base returns non-void;
@@ -77,7 +77,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSign
7777
interface I3 extends Base2 {
7878
~~
7979
!!! error TS2430: Interface 'I3' incorrectly extends interface 'Base2'.
80-
!!! error TS2430: The types of 'a2(...)' are incompatible between these types.
80+
!!! error TS2430: The types returned by 'a2(...)' are incompatible between these types.
8181
!!! error TS2430: Type 'string' is not assignable to type 'T'.
8282
!!! error TS2430: 'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
8383
// N's

tests/baselines/reference/callSignatureAssignabilityInInheritance3.errors.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSign
2727
Types of property 'a' are incompatible.
2828
Type 'string' is not assignable to type 'Base'.
2929
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance3.ts(100,19): error TS2430: Interface 'I6' incorrectly extends interface 'B'.
30-
The types of 'a2(...)' are incompatible between these types.
30+
The types returned by 'a2(...)' are incompatible between these types.
3131
Type 'string[]' is not assignable to type 'T[]'.
3232
Type 'string' is not assignable to type 'T'.
3333
'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
3434
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance3.ts(109,19): error TS2430: Interface 'I7' incorrectly extends interface 'C'.
35-
The types of 'a2(...)' are incompatible between these types.
35+
The types returned by 'a2(...)' are incompatible between these types.
3636
Type 'T[]' is not assignable to type 'string[]'.
3737
Type 'T' is not assignable to type 'string'.
3838

@@ -172,7 +172,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSign
172172
interface I6 extends B {
173173
~~
174174
!!! error TS2430: Interface 'I6' incorrectly extends interface 'B'.
175-
!!! error TS2430: The types of 'a2(...)' are incompatible between these types.
175+
!!! error TS2430: The types returned by 'a2(...)' are incompatible between these types.
176176
!!! error TS2430: Type 'string[]' is not assignable to type 'T[]'.
177177
!!! error TS2430: Type 'string' is not assignable to type 'T'.
178178
!!! error TS2430: 'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
@@ -187,7 +187,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSign
187187
interface I7 extends C {
188188
~~
189189
!!! error TS2430: Interface 'I7' incorrectly extends interface 'C'.
190-
!!! error TS2430: The types of 'a2(...)' are incompatible between these types.
190+
!!! error TS2430: The types returned by 'a2(...)' are incompatible between these types.
191191
!!! error TS2430: Type 'T[]' is not assignable to type 'string[]'.
192192
!!! error TS2430: Type 'T' is not assignable to type 'string'.
193193
a2: <T>(x: T) => T[]; // error

tests/baselines/reference/complexRecursiveCollections.errors.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
tests/cases/compiler/immutable.ts(341,22): error TS2430: Interface 'Keyed<K, V>' incorrectly extends interface 'Collection<K, V>'.
2-
The types of 'toSeq()' are incompatible between these types.
2+
The types returned by 'toSeq()' are incompatible between these types.
33
Type 'Keyed<K, V>' is not assignable to type 'this'.
44
'Keyed<K, V>' is assignable to the constraint of type 'this', but 'this' could be instantiated with a different subtype of constraint 'Keyed<K, V>'.
55
tests/cases/compiler/immutable.ts(359,22): error TS2430: Interface 'Indexed<T>' incorrectly extends interface 'Collection<number, T>'.
6-
The types of 'toSeq()' are incompatible between these types.
6+
The types returned by 'toSeq()' are incompatible between these types.
77
Type 'Indexed<T>' is not assignable to type 'this'.
88
'Indexed<T>' is assignable to the constraint of type 'this', but 'this' could be instantiated with a different subtype of constraint 'Indexed<T>'.
99
tests/cases/compiler/immutable.ts(391,22): error TS2430: Interface 'Set<T>' incorrectly extends interface 'Collection<never, T>'.
10-
The types of 'toSeq()' are incompatible between these types.
10+
The types returned by 'toSeq()' are incompatible between these types.
1111
Type 'Set<T>' is not assignable to type 'this'.
1212
'Set<T>' is assignable to the constraint of type 'this', but 'this' could be instantiated with a different subtype of constraint 'Set<T>'.
1313

@@ -377,7 +377,7 @@ tests/cases/compiler/immutable.ts(391,22): error TS2430: Interface 'Set<T>' inco
377377
export interface Keyed<K, V> extends Collection<K, V> {
378378
~~~~~
379379
!!! error TS2430: Interface 'Keyed<K, V>' incorrectly extends interface 'Collection<K, V>'.
380-
!!! error TS2430: The types of 'toSeq()' are incompatible between these types.
380+
!!! error TS2430: The types returned by 'toSeq()' are incompatible between these types.
381381
!!! error TS2430: Type 'Keyed<K, V>' is not assignable to type 'this'.
382382
!!! error TS2430: 'Keyed<K, V>' is assignable to the constraint of type 'this', but 'this' could be instantiated with a different subtype of constraint 'Keyed<K, V>'.
383383
toJS(): Object;
@@ -400,7 +400,7 @@ tests/cases/compiler/immutable.ts(391,22): error TS2430: Interface 'Set<T>' inco
400400
export interface Indexed<T> extends Collection<number, T> {
401401
~~~~~~~
402402
!!! error TS2430: Interface 'Indexed<T>' incorrectly extends interface 'Collection<number, T>'.
403-
!!! error TS2430: The types of 'toSeq()' are incompatible between these types.
403+
!!! error TS2430: The types returned by 'toSeq()' are incompatible between these types.
404404
!!! error TS2430: Type 'Indexed<T>' is not assignable to type 'this'.
405405
!!! error TS2430: 'Indexed<T>' is assignable to the constraint of type 'this', but 'this' could be instantiated with a different subtype of constraint 'Indexed<T>'.
406406
toJS(): Array<any>;
@@ -437,7 +437,7 @@ tests/cases/compiler/immutable.ts(391,22): error TS2430: Interface 'Set<T>' inco
437437
export interface Set<T> extends Collection<never, T> {
438438
~~~
439439
!!! error TS2430: Interface 'Set<T>' incorrectly extends interface 'Collection<never, T>'.
440-
!!! error TS2430: The types of 'toSeq()' are incompatible between these types.
440+
!!! error TS2430: The types returned by 'toSeq()' are incompatible between these types.
441441
!!! error TS2430: Type 'Set<T>' is not assignable to type 'this'.
442442
!!! error TS2430: 'Set<T>' is assignable to the constraint of type 'this', but 'this' could be instantiated with a different subtype of constraint 'Set<T>'.
443443
toJS(): Array<any>;

0 commit comments

Comments
 (0)