Skip to content

Commit d12b741

Browse files
Excluded type unions from the generale source types
1 parent 035b9ac commit d12b741

17 files changed

+57
-57
lines changed

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15489,7 +15489,7 @@ namespace ts {
1548915489
}
1549015490
}
1549115491

15492-
if (isLiteralType(source) && !isLiteralType(target)) {
15492+
if (isLiteralType(source) && !(source.flags & TypeFlags.Union) && !isLiteralType(target) && !(target.flags & TypeFlags.Union)) {
1549315493
generalizedSourceType = getTypeNameForErrorDisplay(getBaseTypeOfLiteralType(source));
1549415494
}
1549515495

tests/baselines/reference/bigintIndex.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
tests/cases/compiler/a.ts(2,6): error TS1023: An index signature parameter type must be either 'string' or 'number'.
22
tests/cases/compiler/a.ts(8,11): error TS2538: Type '1n' cannot be used as an index type.
3-
tests/cases/compiler/a.ts(14,1): error TS2322: Type 'bigint' is not assignable to type 'string | number | symbol'.
3+
tests/cases/compiler/a.ts(14,1): error TS2322: Type '123n' is not assignable to type 'string | number | symbol'.
44
tests/cases/compiler/a.ts(19,12): error TS2538: Type 'bigint' cannot be used as an index type.
55
tests/cases/compiler/b.ts(2,12): error TS1136: Property assignment expected.
66
tests/cases/compiler/b.ts(2,14): error TS1005: ';' expected.
@@ -29,7 +29,7 @@ tests/cases/compiler/b.ts(4,12): error TS2464: A computed property name must be
2929
key = Symbol();
3030
key = 123n; // should error
3131
~~~
32-
!!! error TS2322: Type 'bigint' is not assignable to type 'string | number | symbol'.
32+
!!! error TS2322: Type '123n' is not assignable to type 'string | number | symbol'.
3333

3434
// Show correct usage of bigint index: explicitly convert to string
3535
const bigNum: bigint = 0n;

tests/baselines/reference/checkJsdocReturnTag2.errors.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
tests/cases/conformance/jsdoc/returns.js(6,5): error TS2322: Type 'number' is not assignable to type 'string'.
2-
tests/cases/conformance/jsdoc/returns.js(13,5): error TS2322: Type 'number | boolean' is not assignable to type 'string | number'.
3-
Type 'boolean' is not assignable to type 'string | number'.
2+
tests/cases/conformance/jsdoc/returns.js(13,5): error TS2322: Type 'true | 5' is not assignable to type 'string | number'.
3+
Type 'true' is not assignable to type 'string | number'.
44

55

66
==== tests/cases/conformance/jsdoc/returns.js (2 errors) ====
@@ -20,6 +20,6 @@ tests/cases/conformance/jsdoc/returns.js(13,5): error TS2322: Type 'number | boo
2020
function f1() {
2121
return 5 || true;
2222
~~~~~~~~~~~~~~~~~
23-
!!! error TS2322: Type 'number | boolean' is not assignable to type 'string | number'.
24-
!!! error TS2322: Type 'boolean' is not assignable to type 'string | number'.
23+
!!! error TS2322: Type 'true | 5' is not assignable to type 'string | number'.
24+
!!! error TS2322: Type 'true' is not assignable to type 'string | number'.
2525
}

tests/baselines/reference/classPropertyErrorOnNameOnly.errors.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
tests/cases/compiler/classPropertyErrorOnNameOnly.ts(7,3): error TS2322: Type '(val: Values) => "1" | "2" | "3" | "4" | "5" | undefined' is not assignable to type 'FuncType'.
2-
Type 'string | undefined' is not assignable to type 'string'.
2+
Type '"1" | "2" | "3" | "4" | "5" | undefined' is not assignable to type 'string'.
33
Type 'undefined' is not assignable to type 'string'.
44
tests/cases/compiler/classPropertyErrorOnNameOnly.ts(24,7): error TS2322: Type '(val: Values) => "1" | "2" | "3" | "4" | "5" | undefined' is not assignable to type 'FuncType'.
5-
Type 'string | undefined' is not assignable to type 'string'.
5+
Type '"1" | "2" | "3" | "4" | "5" | undefined' is not assignable to type 'string'.
66
Type 'undefined' is not assignable to type 'string'.
77

88

@@ -16,7 +16,7 @@ tests/cases/compiler/classPropertyErrorOnNameOnly.ts(24,7): error TS2322: Type '
1616
insideClass: FuncType = function(val) { // error span goes from here
1717
~~~~~~~~~~~
1818
!!! error TS2322: Type '(val: Values) => "1" | "2" | "3" | "4" | "5" | undefined' is not assignable to type 'FuncType'.
19-
!!! error TS2322: Type 'string | undefined' is not assignable to type 'string'.
19+
!!! error TS2322: Type '"1" | "2" | "3" | "4" | "5" | undefined' is not assignable to type 'string'.
2020
!!! error TS2322: Type 'undefined' is not assignable to type 'string'.
2121
switch (val) {
2222
case 1:
@@ -37,7 +37,7 @@ tests/cases/compiler/classPropertyErrorOnNameOnly.ts(24,7): error TS2322: Type '
3737
const outsideClass: FuncType = function(val) { // compare to errors only on this line in this case
3838
~~~~~~~~~~~~
3939
!!! error TS2322: Type '(val: Values) => "1" | "2" | "3" | "4" | "5" | undefined' is not assignable to type 'FuncType'.
40-
!!! error TS2322: Type 'string | undefined' is not assignable to type 'string'.
40+
!!! error TS2322: Type '"1" | "2" | "3" | "4" | "5" | undefined' is not assignable to type 'string'.
4141
!!! error TS2322: Type 'undefined' is not assignable to type 'string'.
4242
switch (val) {
4343
case 1:

tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.errors.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ 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"]'.
5+
Type '"text" | "email"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"] & ChannelOfType<T, EmailChannel>["type"]'.
66
Type 'string' is not assignable to type 'ChannelOfType<T, TextChannel>["type"] & ChannelOfType<T, EmailChannel>["type"]'.
77
Type 'string' 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"]'.
9+
Type '"text" | "email"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
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'.
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"'.
15+
Type '"text" | "email"' 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'.
1818
'"text"' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '"text" | "email"'.
@@ -60,17 +60,17 @@ 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"]'.
63+
!!! error TS2322: Type '"text" | "email"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"] & ChannelOfType<T, EmailChannel>["type"]'.
6464
!!! error TS2322: Type 'string' is not assignable to type 'ChannelOfType<T, TextChannel>["type"] & ChannelOfType<T, EmailChannel>["type"]'.
6565
!!! error TS2322: Type 'string' 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"]'.
67+
!!! error TS2322: Type '"text" | "email"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
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'.
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"'.
73+
!!! error TS2322: Type '"text" | "email"' 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'.
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"'.

tests/baselines/reference/conditionalTypes1.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(159,5): error TS2
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'.
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'.
5050
Type 'string' 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'.
@@ -285,7 +285,7 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(288,43): error TS
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'.
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'.
290290
!!! error TS2322: Type 'string' 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'.

tests/baselines/reference/controlFlowArrayErrors.errors.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ tests/cases/compiler/controlFlowArrayErrors.ts(11,9): error TS7034: Variable 'x'
44
tests/cases/compiler/controlFlowArrayErrors.ts(13,13): error TS7005: Variable 'x' implicitly has an 'any[]' type.
55
tests/cases/compiler/controlFlowArrayErrors.ts(19,9): error TS7034: Variable 'x' implicitly has type 'any[]' in some locations where its type cannot be determined.
66
tests/cases/compiler/controlFlowArrayErrors.ts(22,9): error TS7005: Variable 'x' implicitly has an 'any[]' type.
7-
tests/cases/compiler/controlFlowArrayErrors.ts(29,12): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'.
8-
tests/cases/compiler/controlFlowArrayErrors.ts(34,12): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'.
7+
tests/cases/compiler/controlFlowArrayErrors.ts(29,12): error TS2345: Argument of type 'true' is not assignable to parameter of type 'string | number'.
8+
tests/cases/compiler/controlFlowArrayErrors.ts(34,12): error TS2345: Argument of type 'true' is not assignable to parameter of type 'string | number'.
99
tests/cases/compiler/controlFlowArrayErrors.ts(48,12): error TS2345: Argument of type 'number' is not assignable to parameter of type 'never'.
1010
tests/cases/compiler/controlFlowArrayErrors.ts(56,12): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
1111
tests/cases/compiler/controlFlowArrayErrors.ts(60,11): error TS7034: Variable 'x' implicitly has type 'any[]' in some locations where its type cannot be determined.
@@ -55,14 +55,14 @@ tests/cases/compiler/controlFlowArrayErrors.ts(63,9): error TS7005: Variable 'x'
5555
x = [5, "hello"]; // Non-evolving array
5656
x.push(true); // Error
5757
~~~~
58-
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'.
58+
!!! error TS2345: Argument of type 'true' is not assignable to parameter of type 'string | number'.
5959
}
6060

6161
function f5() {
6262
let x = [5, "hello"]; // Non-evolving array
6363
x.push(true); // Error
6464
~~~~
65-
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'.
65+
!!! error TS2345: Argument of type 'true' is not assignable to parameter of type 'string | number'.
6666
}
6767

6868
function f6() {

tests/baselines/reference/destructuringParameterDeclaration2.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(
1313
Property 'z' is missing in type '{}' but required in type '{ z: number; }'.
1414
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(36,6): error TS2322: Type 'boolean' is not assignable to type 'number'.
1515
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(37,6): error TS2322: Type 'boolean' is not assignable to type 'number'.
16-
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(38,6): error TS2322: Type 'boolean' is not assignable to type 'string | number'.
16+
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(38,6): error TS2322: Type 'true' is not assignable to type 'string | number'.
1717
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(39,11): error TS2322: Type 'boolean' is not assignable to type '[[any]]'.
1818
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(40,13): error TS2322: Type 'string' is not assignable to type 'number'.
1919
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(46,13): error TS2463: A binding pattern parameter cannot be optional in an implementation signature.
@@ -98,7 +98,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(
9898
!!! error TS2322: Type 'boolean' is not assignable to type 'number'.
9999
c3({ b: true }); // Error, implied type is { b: number|string }.
100100
~
101-
!!! error TS2322: Type 'boolean' is not assignable to type 'string | number'.
101+
!!! error TS2322: Type 'true' is not assignable to type 'string | number'.
102102
!!! related TS6500 tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts:29:20: The expected type comes from property 'b' which is declared here on type '{ b: string | number; }'
103103
c5([1, 2, false, true]); // Error, implied type is [any, any, [[any]]]
104104
~~~~~

tests/baselines/reference/destructuringParameterDeclaration4.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(14,17): error TS1047: A rest parameter cannot be optional.
22
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(15,16): error TS1048: A rest parameter cannot have an initializer.
3-
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(20,19): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'.
3+
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(20,19): error TS2345: Argument of type 'true' is not assignable to parameter of type 'string | number'.
44
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(21,7): error TS2552: Cannot find name 'array2'. Did you mean 'Array'?
55
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(22,11): error TS2322: Type 'string' is not assignable to type '[[any]]'.
66
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(23,4): error TS2345: Argument of type '[number, number]' is not assignable to parameter of type '[any, any, [[any]]]'.
@@ -37,7 +37,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(
3737

3838
a1(1, 2, "hello", true); // Error, parameter type is (number|string)[]
3939
~~~~
40-
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'.
40+
!!! error TS2345: Argument of type 'true' is not assignable to parameter of type 'string | number'.
4141
a1(...array2); // Error parameter type is (number|string)[]
4242
~~~~~~
4343
!!! error TS2552: Cannot find name 'array2'. Did you mean 'Array'?

tests/baselines/reference/intersectionPropertyCheck.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ tests/cases/compiler/intersectionPropertyCheck.ts(4,5): error TS2322: Type '{ a:
66
tests/cases/compiler/intersectionPropertyCheck.ts(7,3): error TS2322: Type 'T & { a: boolean; }' is not assignable to type '{ a?: string | undefined; }'.
77
Types of property 'a' are incompatible.
88
Type 'boolean' is not assignable to type 'string | undefined'.
9-
tests/cases/compiler/intersectionPropertyCheck.ts(17,22): error TS2322: Type 'boolean' is not assignable to type 'string[] | undefined'.
9+
tests/cases/compiler/intersectionPropertyCheck.ts(17,22): error TS2322: Type 'true' is not assignable to type 'string[] | undefined'.
1010

1111

1212
==== tests/cases/compiler/intersectionPropertyCheck.ts (4 errors) ====
@@ -40,7 +40,7 @@ tests/cases/compiler/intersectionPropertyCheck.ts(17,22): error TS2322: Type 'bo
4040
function test<T extends object>(value: T): Test {
4141
return { ...value, hi: true }
4242
~~
43-
!!! error TS2322: Type 'boolean' is not assignable to type 'string[] | undefined'.
43+
!!! error TS2322: Type 'true' is not assignable to type 'string[] | undefined'.
4444
!!! related TS6500 tests/cases/compiler/intersectionPropertyCheck.ts:13:12: The expected type comes from property 'hi' which is declared here on type 'Test'
4545
}
4646

tests/baselines/reference/noErrorTruncation.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/compiler/noErrorTruncation.ts(10,7): error TS2322: Type 'number' is not assignable to type 'SomeLongOptionA | SomeLongOptionB | SomeLongOptionC | SomeLongOptionD | SomeLongOptionE | SomeLongOptionF'.
1+
tests/cases/compiler/noErrorTruncation.ts(10,7): error TS2322: Type '42' is not assignable to type 'SomeLongOptionA | SomeLongOptionB | SomeLongOptionC | SomeLongOptionD | SomeLongOptionE | SomeLongOptionF'.
22

33

44
==== tests/cases/compiler/noErrorTruncation.ts (1 errors) ====
@@ -13,7 +13,7 @@ tests/cases/compiler/noErrorTruncation.ts(10,7): error TS2322: Type 'number' is
1313

1414
const x: SomeLongOptionA
1515
~
16-
!!! error TS2322: Type 'number' is not assignable to type 'SomeLongOptionA | SomeLongOptionB | SomeLongOptionC | SomeLongOptionD | SomeLongOptionE | SomeLongOptionF'.
16+
!!! error TS2322: Type '42' is not assignable to type 'SomeLongOptionA | SomeLongOptionB | SomeLongOptionC | SomeLongOptionD | SomeLongOptionE | SomeLongOptionF'.
1717
| SomeLongOptionB
1818
| SomeLongOptionC
1919
| SomeLongOptionD

0 commit comments

Comments
 (0)