You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Extra check in assignment of intersections with generic constituents (#37537)
* Consolidated extra property check with intersections
* Fix comment
* Add tests
* Properly propagate intersectionState
* Route property check through recursive type tracking logic
* Accept new baselines
* Skip check when apparent type of source is never
* Accept new baselines
* Only check when apparent type of source is a structured type
!!! error TS2322: Type '"text" | "email"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"] & ChannelOfType<T, EmailChannel>["type"]'.
67
64
!!! error TS2322: Type '"text"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"] & ChannelOfType<T, EmailChannel>["type"]'.
68
65
!!! 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'.
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"'.
72
-
!!! error TS2322: Type 'T' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
73
-
!!! error TS2322: Type '"text" | "email"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
74
-
!!! error TS2322: Type '"text"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
75
-
!!! error TS2322: Type '"text"' is not assignable to type 'T & "text"'.
76
-
!!! error TS2322: Type '"text"' is not assignable to type 'T'.
77
-
!!! error TS2322: '"text"' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '"text" | "email"'.
78
-
!!! error TS2322: Type 'T' is not assignable to type 'T & "text"'.
79
-
!!! error TS2322: Type '"text" | "email"' is not assignable to type 'T & "text"'.
80
-
!!! error TS2322: Type '"text"' is not assignable to type 'T & "text"'.
81
-
!!! error TS2322: Type '"text"' is not assignable to type 'T'.
82
-
!!! error TS2322: '"text"' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '"text" | "email"'.
83
-
!!! error TS2322: Type 'T' is not assignable to type '"text"'.
84
-
!!! error TS2322: Type '"text" | "email"' is not assignable to type '"text"'.
85
-
!!! error TS2322: Type '"email"' is not assignable to type '"text"'.
66
+
!!! error TS2322: Type 'T' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
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'.
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"'.
72
+
!!! error TS2322: Type 'T' is not assignable to type 'T & "text"'.
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'.
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"'.
77
+
!!! error TS2322: Type 'T' is not assignable to type '"text"'.
78
+
!!! error TS2322: Type '"text" | "email"' is not assignable to type '"text"'.
79
+
!!! error TS2322: Type '"email"' is not assignable to type '"text"'.
tests/cases/compiler/intersectionPropertyCheck.ts(1,68): error TS2322: Type '{ x: string; y: number; }' is not assignable to type '{ x: string; }'.
2
+
Object literal may only specify known properties, and 'y' does not exist in type '{ x: string; }'.
3
+
tests/cases/compiler/intersectionPropertyCheck.ts(4,5): error TS2322: Type '{ a: { y: string; }; }' is not assignable to type '{ a?: { x?: number | undefined; } | undefined; } & { c?: string | undefined; }'.
4
+
Types of property 'a' are incompatible.
5
+
Type '{ y: string; }' has no properties in common with type '{ x?: number | undefined; }'.
6
+
tests/cases/compiler/intersectionPropertyCheck.ts(7,3): error TS2322: Type 'T & { a: boolean; }' is not assignable to type '{ a?: string | undefined; }'.
7
+
Types of property 'a' are incompatible.
8
+
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'.
!!! error TS2322: Type '{ x: string; y: number; }' is not assignable to type '{ x: string; }'.
16
+
!!! error TS2322: Object literal may only specify known properties, and 'y' does not exist in type '{ x: string; }'.
17
+
!!! related TS6500 tests/cases/compiler/intersectionPropertyCheck.ts:1:12: The expected type comes from property 'a' which is declared here on type '{ a: { x: string; }; } & { c: number; }'
18
+
19
+
declare let wrong: { a: { y: string } };
20
+
let weak: { a?: { x?: number } } & { c?: string } = wrong; // Nested weak object type
21
+
~~~~
22
+
!!! error TS2322: Type '{ a: { y: string; }; }' is not assignable to type '{ a?: { x?: number | undefined; } | undefined; } & { c?: string | undefined; }'.
23
+
!!! error TS2322: Types of property 'a' are incompatible.
24
+
!!! error TS2322: Type '{ y: string; }' has no properties in common with type '{ x?: number | undefined; }'.
25
+
26
+
function foo<T extends object>(x: { a?: string }, y: T & { a: boolean }) {
27
+
x = y; // Mismatched property in source intersection
28
+
~
29
+
!!! error TS2322: Type 'T & { a: boolean; }' is not assignable to type '{ a?: string | undefined; }'.
30
+
!!! error TS2322: Types of property 'a' are incompatible.
31
+
!!! error TS2322: Type 'boolean' is not assignable to type 'string | undefined'.
32
+
}
33
+
34
+
// Repro from #36637
35
+
36
+
interface Test {
37
+
readonly hi?: string[]
38
+
}
39
+
40
+
function test<T extends object>(value: T): Test {
41
+
return { ...value, hi: true }
42
+
~~
43
+
!!! error TS2322: Type 'true' is not assignable to type 'string[] | undefined'.
44
+
!!! related TS6500 tests/cases/compiler/intersectionPropertyCheck.ts:13:12: The expected type comes from property 'hi' which is declared here on type 'Test'
0 commit comments