Skip to content

Commit d4825ab

Browse files
I did everything you said I followed all the rules
1 parent 99cdb64 commit d4825ab

15 files changed

+89
-79
lines changed

src/compiler/checker.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15489,13 +15489,23 @@ namespace ts {
1548915489
}
1549015490
}
1549115491

15492-
if (isLiteralType(source) && !forEachType(target, isUnitType)) {
15492+
if (isLiteralType(source) && !typeCouldHaveNoTopLevelSingletonTypes(target)) {
1549315493
generalizedSourceType = getTypeNameForErrorDisplay(getBaseTypeOfLiteralType(source));
1549415494
}
1549515495

1549615496
reportError(message, generalizedSourceType, targetType);
1549715497
}
1549815498

15499+
function typeCouldHaveNoTopLevelSingletonTypes(type: Type) {
15500+
return forEachType(type, typeCouldHaveNoTopLevelSingletonTypesWorker);
15501+
}
15502+
15503+
function typeCouldHaveNoTopLevelSingletonTypesWorker(type: Type): boolean {
15504+
return (type.flags & TypeFlags.Intersection)
15505+
? !!forEach((type as IntersectionType).types, typeCouldHaveNoTopLevelSingletonTypesWorker)
15506+
: isUnitType(type) || !!(type.flags & TypeFlags.Instantiable);
15507+
}
15508+
1549915509
function tryElaborateErrorsForPrimitivesAndObjects(source: Type, target: Type) {
1550015510
const sourceType = symbolValueDeclarationIsContextSensitive(source.symbol) ? typeToString(source, source.symbol.valueDeclaration) : typeToString(source);
1550115511
const targetType = symbolValueDeclarationIsContextSensitive(target.symbol) ? typeToString(target, target.symbol.valueDeclaration) : typeToString(target);

tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.errors.txt

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ tests/cases/compiler/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.t
22
Type '{ type: T; localChannelId: string; }' is not assignable to type 'Pick<ChannelOfType<T, TextChannel> | ChannelOfType<T, EmailChannel>, "type">'.
33
Types of property 'type' are incompatible.
44
Type 'T' is not assignable to type 'ChannelOfType<T, TextChannel>["type"] & ChannelOfType<T, EmailChannel>["type"]'.
5-
Type 'string' is not assignable to type 'ChannelOfType<T, TextChannel>["type"] & ChannelOfType<T, EmailChannel>["type"]'.
6-
Type 'string' is not assignable to type 'ChannelOfType<T, TextChannel>["type"] & ChannelOfType<T, EmailChannel>["type"]'.
7-
Type 'string' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
5+
Type '"text" | "email"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"] & ChannelOfType<T, EmailChannel>["type"]'.
6+
Type '"text"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"] & ChannelOfType<T, EmailChannel>["type"]'.
7+
Type '"text"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
88
Type 'T' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
9-
Type 'string' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
10-
Type 'string' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
11-
Type 'string' is not assignable to type 'T & "text"'.
12-
Type 'string' is not assignable to type 'T'.
9+
Type '"text" | "email"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
10+
Type '"text"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
11+
Type '"text"' is not assignable to type 'T & "text"'.
12+
Type '"text"' is not assignable to type 'T'.
1313
'"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"'.
15-
Type 'string' is not assignable to type 'T & "text"'.
16-
Type 'string' is not assignable to type 'T & "text"'.
17-
Type 'string' is not assignable to type 'T'.
15+
Type '"text" | "email"' is not assignable to type 'T & "text"'.
16+
Type '"text"' is not assignable to type 'T & "text"'.
17+
Type '"text"' is not assignable to type 'T'.
1818
'"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"'.
@@ -60,19 +60,19 @@ tests/cases/compiler/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.t
6060
!!! error TS2322: Type '{ type: T; localChannelId: string; }' is not assignable to type 'Pick<ChannelOfType<T, TextChannel> | ChannelOfType<T, EmailChannel>, "type">'.
6161
!!! error TS2322: Types of property 'type' are incompatible.
6262
!!! error TS2322: Type 'T' is not assignable to type 'ChannelOfType<T, TextChannel>["type"] & ChannelOfType<T, EmailChannel>["type"]'.
63-
!!! error TS2322: Type 'string' is not assignable to type 'ChannelOfType<T, TextChannel>["type"] & ChannelOfType<T, EmailChannel>["type"]'.
64-
!!! error TS2322: Type 'string' is not assignable to type 'ChannelOfType<T, TextChannel>["type"] & ChannelOfType<T, EmailChannel>["type"]'.
65-
!!! error TS2322: Type 'string' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
63+
!!! error TS2322: Type '"text" | "email"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"] & ChannelOfType<T, EmailChannel>["type"]'.
64+
!!! error TS2322: Type '"text"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"] & ChannelOfType<T, EmailChannel>["type"]'.
65+
!!! error TS2322: Type '"text"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
6666
!!! error TS2322: Type 'T' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
67-
!!! error TS2322: Type 'string' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
68-
!!! error TS2322: Type 'string' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
69-
!!! error TS2322: Type 'string' is not assignable to type 'T & "text"'.
70-
!!! error TS2322: Type 'string' is not assignable to type 'T'.
67+
!!! error TS2322: Type '"text" | "email"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
68+
!!! error TS2322: Type '"text"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
69+
!!! error TS2322: Type '"text"' is not assignable to type 'T & "text"'.
70+
!!! error TS2322: Type '"text"' is not assignable to type 'T'.
7171
!!! 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"'.
73-
!!! error TS2322: Type 'string' is not assignable to type 'T & "text"'.
74-
!!! error TS2322: Type 'string' is not assignable to type 'T & "text"'.
75-
!!! error TS2322: Type 'string' is not assignable to type 'T'.
73+
!!! error TS2322: Type '"text" | "email"' is not assignable to type 'T & "text"'.
74+
!!! error TS2322: Type '"text"' is not assignable to type 'T & "text"'.
75+
!!! error TS2322: Type '"text"' is not assignable to type 'T'.
7676
!!! 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"'.

tests/baselines/reference/conditionalTypes1.errors.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(159,5): error TS2
4343
'ZeroOf<T>' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string | number'.
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)'.
46-
Type 'number' is not assignable to type 'T'.
46+
Type '0' is not assignable to type 'T'.
4747
'0' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string | number'.
48-
Type 'string | number' is not assignable to type 'T'.
48+
Type '"" | 0' is not assignable to type 'T'.
4949
'"" | 0' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string | number'.
50-
Type 'string' is not assignable to type 'T'.
50+
Type '""' is not assignable to type 'T'.
5151
'""' 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>'.
@@ -283,11 +283,11 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(288,43): error TS
283283
!!! error TS2322: 'ZeroOf<T>' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string | number'.
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)'.
286-
!!! error TS2322: Type 'number' is not assignable to type 'T'.
286+
!!! error TS2322: Type '0' is not assignable to type 'T'.
287287
!!! error TS2322: '0' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string | number'.
288-
!!! error TS2322: Type 'string | number' is not assignable to type 'T'.
288+
!!! error TS2322: Type '"" | 0' is not assignable to type 'T'.
289289
!!! error TS2322: '"" | 0' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string | number'.
290-
!!! error TS2322: Type 'string' is not assignable to type 'T'.
290+
!!! error TS2322: Type '""' is not assignable to type 'T'.
291291
!!! 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
~

tests/baselines/reference/constructorImplementationWithDefaultValues2.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorImplementationWithDefaultValues2.ts(3,17): error TS2322: Type 'number' is not assignable to type 'string'.
2-
tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorImplementationWithDefaultValues2.ts(10,17): error TS2322: Type 'number' is not assignable to type 'T'.
2+
tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorImplementationWithDefaultValues2.ts(10,17): error TS2322: Type '1' is not assignable to type 'T'.
33
'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'.
@@ -21,7 +21,7 @@ tests/cases/conformance/classes/constructorDeclarations/constructorParameters/co
2121
constructor(x: T, y: U);
2222
constructor(x: T = 1, public y: U = x) { // error
2323
~~~~~~~~
24-
!!! error TS2322: Type 'number' is not assignable to type 'T'.
24+
!!! error TS2322: Type '1' is not assignable to type 'T'.
2525
!!! 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'.

tests/baselines/reference/derivedGenericClassWithAny.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericC
22
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(11,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
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.
5-
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(30,18): error TS2322: Type 'string' is not assignable to type 'T'.
5+
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(30,18): error TS2322: Type '""' is not assignable to type 'T'.
66
'""' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'.
7-
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(32,9): error TS2322: Type 'string' is not assignable to type 'T'.
7+
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(32,9): error TS2322: Type '""' is not assignable to type 'T'.
88
'""' 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.
@@ -51,12 +51,12 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericC
5151
~
5252
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
5353
~~~~~~~~~~
54-
!!! error TS2322: Type 'string' is not assignable to type 'T'.
54+
!!! error TS2322: Type '""' is not assignable to type 'T'.
5555
!!! 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
~~~~~~~~~~
59-
!!! error TS2322: Type 'string' is not assignable to type 'T'.
59+
!!! error TS2322: Type '""' is not assignable to type 'T'.
6060
!!! error TS2322: '""' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'.
6161
}
6262
}

tests/baselines/reference/genericCallWithFunctionTypedArguments.errors.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFun
22
Type 'string' is not assignable to type '1'.
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.
5-
Type 'number' is not assignable to type 'T'.
5+
Type '1' is not assignable to type 'T'.
66
'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.
9-
Type 'number' is not assignable to type 'T'.
9+
Type '1' is not assignable to type 'T'.
1010
'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.
13-
Type 'number' is not assignable to type 'T'.
13+
Type '1' is not assignable to type 'T'.
1414
'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'.
@@ -53,21 +53,21 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFun
5353
~~~~~~~~~~~~
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.
56-
!!! error TS2345: Type 'number' is not assignable to type 'T'.
56+
!!! error TS2345: Type '1' is not assignable to type 'T'.
5757
!!! 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.
64-
!!! error TS2345: Type 'number' is not assignable to type 'T'.
64+
!!! error TS2345: Type '1' is not assignable to type 'T'.
6565
!!! 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.
70-
!!! error TS2345: Type 'number' is not assignable to type 'T'.
70+
!!! error TS2345: Type '1' is not assignable to type 'T'.
7171
!!! 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
~~~~~~~~

0 commit comments

Comments
 (0)