Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 769a2f2

Browse filesBrowse files
Eased up on some of the more aggressive reporting changes
1 parent af4ea60 commit 769a2f2
Copy full SHA for 769a2f2

16 files changed

+57-55Lines changed: 57 additions & 55 deletions
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/checker.ts‎

Copy file name to clipboardExpand all lines: src/compiler/checker.ts
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4073,9 +4073,6 @@ namespace ts {
40734073
leftStr = getTypeNameForErrorDisplay(left);
40744074
rightStr = getTypeNameForErrorDisplay(right);
40754075
}
4076-
else if (isLiteralType(left) && !isLiteralType(right)) {
4077-
leftStr = getTypeNameForErrorDisplay(getBaseTypeOfLiteralType(left))
4078-
}
40794076
return [leftStr, rightStr];
40804077
}
40814078

@@ -15458,6 +15455,7 @@ namespace ts {
1545815455
function reportRelationError(message: DiagnosticMessage | undefined, source: Type, target: Type) {
1545915456
if (incompatibleStack.length) reportIncompatibleStack();
1546015457
const [sourceType, targetType] = getTypeNamesForErrorDisplay(source, target);
15458+
let generalizedSourceType = sourceType;
1546115459

1546215460
if (target.flags & TypeFlags.TypeParameter) {
1546315461
const constraint = getBaseConstraintOfType(target);
@@ -15491,7 +15489,11 @@ namespace ts {
1549115489
}
1549215490
}
1549315491

15494-
reportError(message, sourceType, targetType);
15492+
if (isLiteralType(source) && !isLiteralType(target)) {
15493+
generalizedSourceType = getTypeNameForErrorDisplay(getBaseTypeOfLiteralType(source))
15494+
}
15495+
15496+
reportError(message, generalizedSourceType, targetType);
1549515497
}
1549615498

1549715499
function tryElaborateErrorsForPrimitivesAndObjects(source: Type, target: Type) {
Collapse file

‎src/testRunner/unittests/tsserver/openFile.ts‎

Copy file name to clipboardExpand all lines: src/testRunner/unittests/tsserver/openFile.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ bar();`
175175
file,
176176
syntax: [],
177177
semantic: [
178-
createDiagnostic(locationOfY.start, locationOfY.end, Diagnostics.Type_0_is_not_assignable_to_type_1, ["number", "string"]),
178+
createDiagnostic(locationOfY.start, locationOfY.end, Diagnostics.Type_0_is_not_assignable_to_type_1, ["10", "string"]),
179179
],
180180
suggestion: []
181181
},
Collapse file

‎src/testRunner/unittests/tsserver/projectReferenceErrors.ts‎

Copy file name to clipboardExpand all lines: src/testRunner/unittests/tsserver/projectReferenceErrors.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ fnErr();
166166
{ line: 6, offset: 12 },
167167
{ line: 6, offset: 13 },
168168
Diagnostics.Type_0_is_not_assignable_to_type_1,
169-
["number", "string"],
169+
["10", "string"],
170170
"error",
171171
)
172172
],
@@ -235,7 +235,7 @@ fnErr();
235235
{ line: 6, offset: 5 },
236236
{ line: 6, offset: 6 },
237237
Diagnostics.Type_0_is_not_assignable_to_type_1,
238-
["number", "string"],
238+
["10", "string"],
239239
"error",
240240
)
241241
],
Collapse file

‎tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.errors.txt‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.errors.txt
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ tests/cases/compiler/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.t
1010
Type 'string' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
1111
Type 'string' is not assignable to type 'T & "text"'.
1212
Type 'string' is not assignable to type 'T'.
13-
'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '"text" | "email"'.
13+
'"text"' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '"text" | "email"'.
1414
Type 'T' is not assignable to type 'T & "text"'.
1515
Type 'string' is not assignable to type 'T & "text"'.
1616
Type 'string' is not assignable to type 'T & "text"'.
1717
Type 'string' is not assignable to type 'T'.
18-
'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '"text" | "email"'.
18+
'"text"' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '"text" | "email"'.
1919
Type 'T' is not assignable to type '"text"'.
2020
Type '"text" | "email"' is not assignable to type '"text"'.
2121
Type '"email"' is not assignable to type '"text"'.
@@ -68,12 +68,12 @@ tests/cases/compiler/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.t
6868
!!! error TS2322: Type 'string' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
6969
!!! error TS2322: Type 'string' is not assignable to type 'T & "text"'.
7070
!!! error TS2322: Type 'string' is not assignable to type 'T'.
71-
!!! error TS2322: 'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '"text" | "email"'.
71+
!!! error TS2322: '"text"' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '"text" | "email"'.
7272
!!! error TS2322: Type 'T' is not assignable to type 'T & "text"'.
7373
!!! error TS2322: Type 'string' is not assignable to type 'T & "text"'.
7474
!!! error TS2322: Type 'string' is not assignable to type 'T & "text"'.
7575
!!! error TS2322: Type 'string' is not assignable to type 'T'.
76-
!!! error TS2322: 'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '"text" | "email"'.
76+
!!! error TS2322: '"text"' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '"text" | "email"'.
7777
!!! error TS2322: Type 'T' is not assignable to type '"text"'.
7878
!!! error TS2322: Type '"text" | "email"' is not assignable to type '"text"'.
7979
!!! error TS2322: Type '"email"' is not assignable to type '"text"'.
Collapse file

‎tests/baselines/reference/conditionalTypes1.errors.txt‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/conditionalTypes1.errors.txt
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(159,5): error TS2
4444
Type '0 | (T extends string ? "" : false)' is not assignable to type 'T'.
4545
'T' could be instantiated with an arbitrary type which could be unrelated to '0 | (T extends string ? "" : false)'.
4646
Type 'number' is not assignable to type 'T'.
47-
'number' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string | number'.
47+
'0' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string | number'.
4848
Type 'string | number' is not assignable to type 'T'.
49-
'string | number' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string | number'.
49+
'"" | 0' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string | number'.
5050
Type 'string' is not assignable to type 'T'.
51-
'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string | number'.
51+
'""' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string | number'.
5252
tests/cases/conformance/types/conditional/conditionalTypes1.ts(160,5): error TS2322: Type 'T' is not assignable to type 'ZeroOf<T>'.
5353
Type 'string | number' is not assignable to type 'ZeroOf<T>'.
5454
Type 'string' is not assignable to type 'ZeroOf<T>'.
@@ -284,11 +284,11 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(288,43): error TS
284284
!!! error TS2322: Type '0 | (T extends string ? "" : false)' is not assignable to type 'T'.
285285
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to '0 | (T extends string ? "" : false)'.
286286
!!! error TS2322: Type 'number' is not assignable to type 'T'.
287-
!!! error TS2322: 'number' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string | number'.
287+
!!! error TS2322: '0' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string | number'.
288288
!!! error TS2322: Type 'string | number' is not assignable to type 'T'.
289-
!!! error TS2322: 'string | number' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string | number'.
289+
!!! error TS2322: '"" | 0' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string | number'.
290290
!!! error TS2322: Type 'string' is not assignable to type 'T'.
291-
!!! error TS2322: 'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string | number'.
291+
!!! error TS2322: '""' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string | number'.
292292
y = x; // Error
293293
~
294294
!!! error TS2322: Type 'T' is not assignable to type 'ZeroOf<T>'.
Collapse file

‎tests/baselines/reference/constructorImplementationWithDefaultValues2.errors.txt‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/constructorImplementationWithDefaultValues2.errors.txt
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorImplementationWithDefaultValues2.ts(3,17): error TS2322: Type 'number' is not assignable to type 'string'.
22
tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorImplementationWithDefaultValues2.ts(10,17): error TS2322: Type 'number' is not assignable to type 'T'.
3-
'T' could be instantiated with an arbitrary type which could be unrelated to 'number'.
3+
'T' could be instantiated with an arbitrary type which could be unrelated to '1'.
44
tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorImplementationWithDefaultValues2.ts(10,27): error TS2322: Type 'T' is not assignable to type 'U'.
55
'U' could be instantiated with an arbitrary type which could be unrelated to 'T'.
66
tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorImplementationWithDefaultValues2.ts(17,17): error TS2322: Type 'Date' is not assignable to type 'T'.
@@ -22,7 +22,7 @@ tests/cases/conformance/classes/constructorDeclarations/constructorParameters/co
2222
constructor(x: T = 1, public y: U = x) { // error
2323
~~~~~~~~
2424
!!! error TS2322: Type 'number' is not assignable to type 'T'.
25-
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'number'.
25+
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to '1'.
2626
~~~~~~~~~~~~~~~
2727
!!! error TS2322: Type 'T' is not assignable to type 'U'.
2828
!!! error TS2322: 'U' could be instantiated with an arbitrary type which could be unrelated to 'T'.
Collapse file

‎tests/baselines/reference/derivedGenericClassWithAny.errors.txt‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/derivedGenericClassWithAny.errors.txt
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericC
33
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(19,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
44
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(30,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
55
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(30,18): error TS2322: Type 'string' is not assignable to type 'T'.
6-
'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'.
6+
'""' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'.
77
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(32,9): error TS2322: Type 'string' is not assignable to type 'T'.
8-
'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'.
8+
'""' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'.
99
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(41,1): error TS2322: Type 'E<string>' is not assignable to type 'C<number>'.
1010
Types of property 'x' are incompatible.
1111
Type 'string' is not assignable to type 'number'.
@@ -52,12 +52,12 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericC
5252
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
5353
~~~~~~~~~~
5454
!!! error TS2322: Type 'string' is not assignable to type 'T'.
55-
!!! error TS2322: 'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'.
55+
!!! error TS2322: '""' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'.
5656
foo(): T {
5757
return ''; // error
5858
~~~~~~~~~~
5959
!!! error TS2322: Type 'string' is not assignable to type 'T'.
60-
!!! error TS2322: 'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'.
60+
!!! error TS2322: '""' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'.
6161
}
6262
}
6363

Collapse file

‎tests/baselines/reference/genericCallWithFunctionTypedArguments.errors.txt‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/genericCallWithFunctionTypedArguments.errors.txt
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFun
33
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(30,23): error TS2345: Argument of type '(x: T) => string' is not assignable to parameter of type '(a: 1) => string'.
44
Types of parameters 'x' and 'a' are incompatible.
55
Type 'number' is not assignable to type 'T'.
6-
'T' could be instantiated with an arbitrary type which could be unrelated to 'number'.
6+
'T' could be instantiated with an arbitrary type which could be unrelated to '1'.
77
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(33,23): error TS2345: Argument of type '(x: T) => string' is not assignable to parameter of type '(a: 1) => string'.
88
Types of parameters 'x' and 'a' are incompatible.
99
Type 'number' is not assignable to type 'T'.
10-
'T' could be instantiated with an arbitrary type which could be unrelated to 'number'.
10+
'T' could be instantiated with an arbitrary type which could be unrelated to '1'.
1111
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(34,24): error TS2345: Argument of type '(x: T) => string' is not assignable to parameter of type '(a: 1) => string'.
1212
Types of parameters 'x' and 'a' are incompatible.
1313
Type 'number' is not assignable to type 'T'.
14-
'T' could be instantiated with an arbitrary type which could be unrelated to 'number'.
14+
'T' could be instantiated with an arbitrary type which could be unrelated to '1'.
1515
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(35,23): error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => 1'.
1616
Type 'string' is not assignable to type '1'.
1717

@@ -54,21 +54,21 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFun
5454
!!! error TS2345: Argument of type '(x: T) => string' is not assignable to parameter of type '(a: 1) => string'.
5555
!!! error TS2345: Types of parameters 'x' and 'a' are incompatible.
5656
!!! error TS2345: Type 'number' is not assignable to type 'T'.
57-
!!! error TS2345: 'T' could be instantiated with an arbitrary type which could be unrelated to 'number'.
57+
!!! error TS2345: 'T' could be instantiated with an arbitrary type which could be unrelated to '1'.
5858
var r10 = foo2(1, (x) => ''); // string
5959

6060
var r11 = foo3(1, (x: T) => '', ''); // error
6161
~~~~~~~~~~~~
6262
!!! error TS2345: Argument of type '(x: T) => string' is not assignable to parameter of type '(a: 1) => string'.
6363
!!! error TS2345: Types of parameters 'x' and 'a' are incompatible.
6464
!!! error TS2345: Type 'number' is not assignable to type 'T'.
65-
!!! error TS2345: 'T' could be instantiated with an arbitrary type which could be unrelated to 'number'.
65+
!!! error TS2345: 'T' could be instantiated with an arbitrary type which could be unrelated to '1'.
6666
var r11b = foo3(1, (x: T) => '', 1); // error
6767
~~~~~~~~~~~~
6868
!!! error TS2345: Argument of type '(x: T) => string' is not assignable to parameter of type '(a: 1) => string'.
6969
!!! error TS2345: Types of parameters 'x' and 'a' are incompatible.
7070
!!! error TS2345: Type 'number' is not assignable to type 'T'.
71-
!!! error TS2345: 'T' could be instantiated with an arbitrary type which could be unrelated to 'number'.
71+
!!! error TS2345: 'T' could be instantiated with an arbitrary type which could be unrelated to '1'.
7272
var r12 = foo3(1, function (a) { return '' }, 1); // error
7373
~~~~~~~~
7474
!!! error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => 1'.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.