Skip to content

Commit d4fcff2

Browse files
committed
Update message, specialize output for argument-less signatures
1 parent 06908f8 commit d4fcff2

File tree

47 files changed

+193
-169
lines changed

Some content is hidden

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

47 files changed

+193
-169
lines changed

src/compiler/checker.ts

+22-8
Original file line numberDiff line numberDiff line change
@@ -12801,11 +12801,19 @@ namespace ts {
1280112801
path = path.length === 0 ? "new (...)" : `new ${path}(...)`;
1280212802
break;
1280312803
}
12804+
case Diagnostics.Call_signatures_with_no_arguments_have_incompatible_return_types.code: {
12805+
path = path.length === 0 ? "()" : `${path}()`;
12806+
break;
12807+
}
12808+
case Diagnostics.Construct_signatures_with_no_arguments_have_incompatible_return_types.code: {
12809+
path = path.length === 0 ? "new ()" : `new ${path}()`;
12810+
break;
12811+
}
1280412812
default:
1280512813
return Debug.fail(`Unhandled Diagnostic: ${msg.code}`);
1280612814
}
1280712815
}
12808-
reportError(Diagnostics._0_is_incompatible_between_these_types, path);
12816+
reportError(Diagnostics.The_types_of_0_are_incompatible_between_these_types, path);
1280912817
if (info) {
1281012818
// Actually do the last relation error
1281112819
reportRelationError(/*headMessage*/ undefined, ...info);
@@ -14253,7 +14261,7 @@ namespace ts {
1425314261
// of the much more expensive N * M comparison matrix we explore below. We erase type parameters
1425414262
// as they are known to always be the same.
1425514263
for (let i = 0; i < targetSignatures.length; i++) {
14256-
const related = signatureRelatedTo(sourceSignatures[i], targetSignatures[i], /*erase*/ true, reportErrors, incompatibleReporter);
14264+
const related = signatureRelatedTo(sourceSignatures[i], targetSignatures[i], /*erase*/ true, reportErrors, incompatibleReporter(sourceSignatures[i], targetSignatures[i]));
1425714265
if (!related) {
1425814266
return Ternary.False;
1425914267
}
@@ -14267,14 +14275,14 @@ namespace ts {
1426714275
// this regardless of the number of signatures, but the potential costs are prohibitive due
1426814276
// to the quadratic nature of the logic below.
1426914277
const eraseGenerics = relation === comparableRelation || !!compilerOptions.noStrictGenericChecks;
14270-
result = signatureRelatedTo(sourceSignatures[0], targetSignatures[0], eraseGenerics, reportErrors, incompatibleReporter);
14278+
result = signatureRelatedTo(sourceSignatures[0], targetSignatures[0], eraseGenerics, reportErrors, incompatibleReporter(sourceSignatures[0], targetSignatures[0]));
1427114279
}
1427214280
else {
1427314281
outer: for (const t of targetSignatures) {
1427414282
// Only elaborate errors from the first failure
1427514283
let shouldElaborateErrors = reportErrors;
1427614284
for (const s of sourceSignatures) {
14277-
const related = signatureRelatedTo(s, t, /*erase*/ true, shouldElaborateErrors, incompatibleReporter);
14285+
const related = signatureRelatedTo(s, t, /*erase*/ true, shouldElaborateErrors, incompatibleReporter(s, t));
1427814286
if (related) {
1427914287
result &= related;
1428014288
resetErrorInfo(saveErrorInfo);
@@ -14294,12 +14302,18 @@ namespace ts {
1429414302
return result;
1429514303
}
1429614304

14297-
function reportIncompatibleCallSignatureReturn() {
14298-
reportIncompatibleError(Diagnostics.Call_signature_return_types_are_incompatible);
14305+
function reportIncompatibleCallSignatureReturn(siga: Signature, sigb: Signature) {
14306+
if (siga.parameters.length === 0 && sigb.parameters.length === 0) {
14307+
return () => reportIncompatibleError(Diagnostics.Call_signatures_with_no_arguments_have_incompatible_return_types);
14308+
}
14309+
return () => reportIncompatibleError(Diagnostics.Call_signature_return_types_are_incompatible);
1429914310
}
1430014311

14301-
function reportIncompatibleConstructSignatureReturn() {
14302-
reportIncompatibleError(Diagnostics.Construct_signature_return_types_are_incompatible);
14312+
function reportIncompatibleConstructSignatureReturn(siga: Signature, sigb: Signature) {
14313+
if (siga.parameters.length === 0 && sigb.parameters.length === 0) {
14314+
return () => reportIncompatibleError(Diagnostics.Construct_signatures_with_no_arguments_have_incompatible_return_types);
14315+
}
14316+
return () => reportIncompatibleError(Diagnostics.Construct_signature_return_types_are_incompatible);
1430314317
}
1430414318

1430514319
/**

src/compiler/diagnosticMessages.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@
10401040
"code": 1357
10411041
},
10421042

1043-
"'{0}' is incompatible between these types.": {
1043+
"The types of '{0}' are incompatible between these types.": {
10441044
"category": "Error",
10451045
"code": 2200
10461046
},
@@ -1054,6 +1054,16 @@
10541054
"code": 2202,
10551055
"elidedInCompatabilityPyramid": true
10561056
},
1057+
"Call signatures with no arguments have incompatible return types.": {
1058+
"category": "Error",
1059+
"code": 2203,
1060+
"elidedInCompatabilityPyramid": true
1061+
},
1062+
"Construct signatures with no arguments have incompatible return types.": {
1063+
"category": "Error",
1064+
"code": 2204,
1065+
"elidedInCompatabilityPyramid": true
1066+
},
10571067

10581068
"Duplicate identifier '{0}'.": {
10591069
"category": "Error",

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-
'pop(...)' is incompatible between these types.
11+
The types of '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: 'pop(...)' is incompatible between these types.
69+
!!! error TS2322: The types of '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-
'concat(...)' is incompatible between these types.
4+
The types of '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: 'concat(...)' is incompatible between these types.
34+
!!! error TS2322: The types of '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-
'valueOf(...)' is incompatible between these types.
2+
The types of '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: 'valueOf(...)' is incompatible between these types.
26+
!!! error TS2322: The types of '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
@@ -5,7 +5,7 @@ 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-
'(new (...)).then(...)' is incompatible between these types.
8+
The types of '(new (...)).then(...)' are incompatible between these types.
99
Type 'void' is not assignable to type 'PromiseLike<TResult1 | TResult2>'.
1010
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.
1111
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.
@@ -36,7 +36,7 @@ tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration1
3636
async function fn6(): Thenable { } // error
3737
~~~~~~~~
3838
!!! 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.
39-
!!! error TS1055: '(new (...)).then(...)' is incompatible between these types.
39+
!!! error TS1055: The types of '(new (...)).then(...)' are incompatible between these types.
4040
!!! error TS1055: Type 'void' is not assignable to type 'PromiseLike<TResult1 | TResult2>'.
4141
async function fn7() { return; } // valid: Promise<void>
4242
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-
'[Symbol.iterator](...).next(...)' is incompatible between these types.
7+
The types of '[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: '[Symbol.iterator](...).next(...)' is incompatible between these types.
54+
!!! error TS2769: The types of '[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-
'valueOf(...)' is incompatible between these types.
4+
The types of '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: 'valueOf(...)' is incompatible between these types.
19+
!!! error TS2322: The types of '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-
'a(...)' is incompatible between these types.
2+
The types of '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-
'a2(...)' is incompatible between these types.
5+
The types of '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: 'a(...)' is incompatible between these types.
70+
!!! error TS2430: The types of '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: 'a2(...)' is incompatible between these types.
80+
!!! error TS2430: The types of '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-
'a2(...)' is incompatible between these types.
30+
The types of '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-
'a2(...)' is incompatible between these types.
35+
The types of '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: 'a2(...)' is incompatible between these types.
175+
!!! error TS2430: The types of '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: 'a2(...)' is incompatible between these types.
190+
!!! error TS2430: The types of '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

0 commit comments

Comments
 (0)