Skip to content

Commit

Permalink
Add return type specialized message
Browse files Browse the repository at this point in the history
  • Loading branch information
weswigham committed Sep 23, 2019
1 parent f5dc527 commit 8d3038a
Show file tree
Hide file tree
Showing 34 changed files with 139 additions and 131 deletions.
6 changes: 5 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12827,7 +12827,11 @@ namespace ts {
}
}
if (path) {
reportError(Diagnostics.The_types_of_0_are_incompatible_between_these_types, path);
reportError(path[path.length - 1] === ")"
? Diagnostics.The_types_returned_by_0_are_incompatible_between_these_types
: Diagnostics.The_types_of_0_are_incompatible_between_these_types,
path
);
}
else {
// Remove the innermost secondary error as it will duplicate the error already reported by `reportRelationError` on entry
Expand Down
12 changes: 8 additions & 4 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1044,24 +1044,28 @@
"category": "Error",
"code": 2200
},
"The types returned by '{0}' are incompatible between these types.": {
"category": "Error",
"code": 2201
},
"Call signature return types '{0}' and '{1}' are incompatible.": {
"category": "Error",
"code": 2201,
"code": 2202,
"elidedInCompatabilityPyramid": true
},
"Construct signature return types '{0}' and '{1}' are incompatible.": {
"category": "Error",
"code": 2202,
"code": 2203,
"elidedInCompatabilityPyramid": true
},
"Call signatures with no arguments have incompatible return types '{0}' and '{1}'.": {
"category": "Error",
"code": 2203,
"code": 2204,
"elidedInCompatabilityPyramid": true
},
"Construct signatures with no arguments have incompatible return types '{0}' and '{1}'.": {
"category": "Error",
"code": 2204,
"code": 2205,
"elidedInCompatabilityPyramid": true
},

Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/arrayLiterals3.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(17,5): error
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(32,5): error TS2739: Type '(number[] | string[])[]' is missing the following properties from type 'tup': 0, 1
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
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'.
The types of 'pop()' are incompatible between these types.
The types returned by 'pop()' are incompatible between these types.
Type 'string | number' is not assignable to type 'Number'.
Type 'string' is not assignable to type 'Number'.

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

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts(13,1): error TS2322: Type 'A[]' is not assignable to type 'readonly B[]'.
Property 'b' is missing in type 'A' but required in type 'B'.
tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts(18,1): error TS2322: Type 'C<A>' is not assignable to type 'readonly B[]'.
The types of 'concat(...)' are incompatible between these types.
The types returned by 'concat(...)' are incompatible between these types.
Type 'A[]' is not assignable to type 'B[]'.
Type 'A' is not assignable to type 'B'.

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

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tests/cases/conformance/types/primitives/boolean/assignFromBooleanInterface2.ts(14,1): error TS2322: Type 'NotBoolean' is not assignable to type 'Boolean'.
The types of 'valueOf()' are incompatible between these types.
The types returned by 'valueOf()' are incompatible between these types.
Type 'Object' is not assignable to type 'boolean'.
tests/cases/conformance/types/primitives/boolean/assignFromBooleanInterface2.ts(19,1): error TS2322: Type 'Boolean' is not assignable to type 'boolean'.
'boolean' is a primitive, but 'Boolean' is a wrapper object. Prefer using 'boolean' when possible.
Expand All @@ -23,7 +23,7 @@ tests/cases/conformance/types/primitives/boolean/assignFromBooleanInterface2.ts(
a = b;
~
!!! error TS2322: Type 'NotBoolean' is not assignable to type 'Boolean'.
!!! error TS2322: The types of 'valueOf()' are incompatible between these types.
!!! error TS2322: The types returned by 'valueOf()' are incompatible between these types.
!!! error TS2322: Type 'Object' is not assignable to type 'boolean'.

b = a;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration1
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.
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.
Construct signature return types 'Thenable' and 'PromiseLike<T>' are incompatible.
The types of 'then(...)' are incompatible between these types.
The types returned by 'then(...)' are incompatible between these types.
Type 'void' is not assignable to type 'PromiseLike<TResult1 | TResult2>'.
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.
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.
Expand Down Expand Up @@ -38,7 +38,7 @@ tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration1
~~~~~~~~
!!! 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.
!!! error TS1055: Construct signature return types 'Thenable' and 'PromiseLike<T>' are incompatible.
!!! error TS1055: The types of 'then(...)' are incompatible between these types.
!!! error TS1055: The types returned by 'then(...)' are incompatible between these types.
!!! error TS1055: Type 'void' is not assignable to type 'PromiseLike<TResult1 | TResult2>'.
async function fn7() { return; } // valid: Promise<void>
async function fn8() { return 1; } // valid: Promise<number>
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/bigintWithLib.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ tests/cases/compiler/bigintWithLib.ts(16,33): error TS2769: No overload matches
Argument of type 'number[]' is not assignable to parameter of type 'number'.
Overload 2 of 3, '(array: Iterable<bigint>): BigInt64Array', gave the following error.
Argument of type 'number[]' is not assignable to parameter of type 'Iterable<bigint>'.
The types of '[Symbol.iterator]().next(...)' are incompatible between these types.
The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types.
Type 'IteratorResult<number, any>' is not assignable to type 'IteratorResult<bigint, any>'.
Type 'IteratorYieldResult<number>' is not assignable to type 'IteratorResult<bigint, any>'.
Type 'IteratorYieldResult<number>' is not assignable to type 'IteratorYieldResult<bigint>'.
Expand Down Expand Up @@ -51,7 +51,7 @@ tests/cases/compiler/bigintWithLib.ts(43,26): error TS2345: Argument of type '12
!!! error TS2769: Argument of type 'number[]' is not assignable to parameter of type 'number'.
!!! error TS2769: Overload 2 of 3, '(array: Iterable<bigint>): BigInt64Array', gave the following error.
!!! error TS2769: Argument of type 'number[]' is not assignable to parameter of type 'Iterable<bigint>'.
!!! error TS2769: The types of '[Symbol.iterator]().next(...)' are incompatible between these types.
!!! error TS2769: The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types.
!!! error TS2769: Type 'IteratorResult<number, any>' is not assignable to type 'IteratorResult<bigint, any>'.
!!! error TS2769: Type 'IteratorYieldResult<number>' is not assignable to type 'IteratorResult<bigint, any>'.
!!! error TS2769: Type 'IteratorYieldResult<number>' is not assignable to type 'IteratorYieldResult<bigint>'.
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/booleanAssignment.errors.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
tests/cases/compiler/booleanAssignment.ts(2,1): error TS2322: Type '1' is not assignable to type 'Boolean'.
tests/cases/compiler/booleanAssignment.ts(3,1): error TS2322: Type '"a"' is not assignable to type 'Boolean'.
tests/cases/compiler/booleanAssignment.ts(4,1): error TS2322: Type '{}' is not assignable to type 'Boolean'.
The types of 'valueOf()' are incompatible between these types.
The types returned by 'valueOf()' are incompatible between these types.
Type 'Object' is not assignable to type 'boolean'.


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

var o = {};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance.ts(57,15): error TS2430: Interface 'I2' incorrectly extends interface 'Base2'.
The types of 'a(...)' are incompatible between these types.
The types returned by 'a(...)' are incompatible between these types.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance.ts(63,15): error TS2430: Interface 'I3' incorrectly extends interface 'Base2'.
The types of 'a2(...)' are incompatible between these types.
The types returned by 'a2(...)' are incompatible between these types.
Type 'string' is not assignable to type 'T'.
'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.

Expand Down Expand Up @@ -67,7 +67,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSign
interface I2 extends Base2 {
~~
!!! error TS2430: Interface 'I2' incorrectly extends interface 'Base2'.
!!! error TS2430: The types of 'a(...)' are incompatible between these types.
!!! error TS2430: The types returned by 'a(...)' are incompatible between these types.
!!! error TS2430: Type 'string' is not assignable to type 'number'.
// N's
a: (x: number) => string; // error because base returns non-void;
Expand All @@ -77,7 +77,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSign
interface I3 extends Base2 {
~~
!!! error TS2430: Interface 'I3' incorrectly extends interface 'Base2'.
!!! error TS2430: The types of 'a2(...)' are incompatible between these types.
!!! error TS2430: The types returned by 'a2(...)' are incompatible between these types.
!!! error TS2430: Type 'string' is not assignable to type 'T'.
!!! error TS2430: 'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
// N's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSign
Types of property 'a' are incompatible.
Type 'string' is not assignable to type 'Base'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance3.ts(100,19): error TS2430: Interface 'I6' incorrectly extends interface 'B'.
The types of 'a2(...)' are incompatible between these types.
The types returned by 'a2(...)' are incompatible between these types.
Type 'string[]' is not assignable to type 'T[]'.
Type 'string' is not assignable to type 'T'.
'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance3.ts(109,19): error TS2430: Interface 'I7' incorrectly extends interface 'C'.
The types of 'a2(...)' are incompatible between these types.
The types returned by 'a2(...)' are incompatible between these types.
Type 'T[]' is not assignable to type 'string[]'.
Type 'T' is not assignable to type 'string'.

Expand Down Expand Up @@ -172,7 +172,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSign
interface I6 extends B {
~~
!!! error TS2430: Interface 'I6' incorrectly extends interface 'B'.
!!! error TS2430: The types of 'a2(...)' are incompatible between these types.
!!! error TS2430: The types returned by 'a2(...)' are incompatible between these types.
!!! error TS2430: Type 'string[]' is not assignable to type 'T[]'.
!!! error TS2430: Type 'string' is not assignable to type 'T'.
!!! error TS2430: 'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
Expand All @@ -187,7 +187,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSign
interface I7 extends C {
~~
!!! error TS2430: Interface 'I7' incorrectly extends interface 'C'.
!!! error TS2430: The types of 'a2(...)' are incompatible between these types.
!!! error TS2430: The types returned by 'a2(...)' are incompatible between these types.
!!! error TS2430: Type 'T[]' is not assignable to type 'string[]'.
!!! error TS2430: Type 'T' is not assignable to type 'string'.
a2: <T>(x: T) => T[]; // error
Expand Down
12 changes: 6 additions & 6 deletions tests/baselines/reference/complexRecursiveCollections.errors.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
tests/cases/compiler/immutable.ts(341,22): error TS2430: Interface 'Keyed<K, V>' incorrectly extends interface 'Collection<K, V>'.
The types of 'toSeq()' are incompatible between these types.
The types returned by 'toSeq()' are incompatible between these types.
Type 'Keyed<K, V>' is not assignable to type 'this'.
'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>'.
tests/cases/compiler/immutable.ts(359,22): error TS2430: Interface 'Indexed<T>' incorrectly extends interface 'Collection<number, T>'.
The types of 'toSeq()' are incompatible between these types.
The types returned by 'toSeq()' are incompatible between these types.
Type 'Indexed<T>' is not assignable to type 'this'.
'Indexed<T>' is assignable to the constraint of type 'this', but 'this' could be instantiated with a different subtype of constraint 'Indexed<T>'.
tests/cases/compiler/immutable.ts(391,22): error TS2430: Interface 'Set<T>' incorrectly extends interface 'Collection<never, T>'.
The types of 'toSeq()' are incompatible between these types.
The types returned by 'toSeq()' are incompatible between these types.
Type 'Set<T>' is not assignable to type 'this'.
'Set<T>' is assignable to the constraint of type 'this', but 'this' could be instantiated with a different subtype of constraint 'Set<T>'.

Expand Down Expand Up @@ -377,7 +377,7 @@ tests/cases/compiler/immutable.ts(391,22): error TS2430: Interface 'Set<T>' inco
export interface Keyed<K, V> extends Collection<K, V> {
~~~~~
!!! error TS2430: Interface 'Keyed<K, V>' incorrectly extends interface 'Collection<K, V>'.
!!! error TS2430: The types of 'toSeq()' are incompatible between these types.
!!! error TS2430: The types returned by 'toSeq()' are incompatible between these types.
!!! error TS2430: Type 'Keyed<K, V>' is not assignable to type 'this'.
!!! 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>'.
toJS(): Object;
Expand All @@ -400,7 +400,7 @@ tests/cases/compiler/immutable.ts(391,22): error TS2430: Interface 'Set<T>' inco
export interface Indexed<T> extends Collection<number, T> {
~~~~~~~
!!! error TS2430: Interface 'Indexed<T>' incorrectly extends interface 'Collection<number, T>'.
!!! error TS2430: The types of 'toSeq()' are incompatible between these types.
!!! error TS2430: The types returned by 'toSeq()' are incompatible between these types.
!!! error TS2430: Type 'Indexed<T>' is not assignable to type 'this'.
!!! 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>'.
toJS(): Array<any>;
Expand Down Expand Up @@ -437,7 +437,7 @@ tests/cases/compiler/immutable.ts(391,22): error TS2430: Interface 'Set<T>' inco
export interface Set<T> extends Collection<never, T> {
~~~
!!! error TS2430: Interface 'Set<T>' incorrectly extends interface 'Collection<never, T>'.
!!! error TS2430: The types of 'toSeq()' are incompatible between these types.
!!! error TS2430: The types returned by 'toSeq()' are incompatible between these types.
!!! error TS2430: Type 'Set<T>' is not assignable to type 'this'.
!!! 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>'.
toJS(): Array<any>;
Expand Down
Loading

0 comments on commit 8d3038a

Please sign in to comment.