-
Notifications
You must be signed in to change notification settings - Fork 12.8k
/
Copy pathnestedExcessPropertyChecking.types
160 lines (121 loc) · 4.21 KB
/
nestedExcessPropertyChecking.types
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
=== tests/cases/compiler/nestedExcessPropertyChecking.ts ===
type A1 = { x: { a?: string } };
>A1 : { x: { a?: string;}; }
>x : { a?: string | undefined; }
>a : string | undefined
type B1 = { x: { b?: string } };
>B1 : { x: { b?: string;}; }
>x : { b?: string | undefined; }
>b : string | undefined
type C1 = { x: { c: string } };
>C1 : { x: { c: string;}; }
>x : { c: string; }
>c : string
const ab1: A1 & B1 = {} as C1; // Error
>ab1 : A1 & B1
>{} as C1 : C1
>{} : {}
type A2 = { a?: string };
>A2 : { a?: string | undefined; }
>a : string | undefined
type B2 = { b?: string };
>B2 : { b?: string | undefined; }
>b : string | undefined
type C2 = { c: string };
>C2 : { c: string; }
>c : string
const ab2: A2 & B2 = {} as C2; // Error
>ab2 : A2 & B2
>{} as C2 : C2
>{} : {}
enum E { A = "A" }
>E : E
>A : E.A
>"A" : "A"
let x: { nope?: any } = E.A; // Error
>x : { nope?: any; }
>nope : any
>E.A : E
>E : typeof E
>A : E
let y: { nope?: any } = "A"; // Error
>y : { nope?: any; }
>nope : any
>"A" : "A"
// Repros from #51043
type OverridesInput = {
>OverridesInput : { someProp?: "A" | "B" | undefined; }
someProp?: 'A' | 'B'
>someProp : "A" | "B" | undefined
}
const foo1: Partial<{ something: any }> & { variables: {
>foo1 : Partial<{ something: any; }> & { variables: { overrides?: OverridesInput;} & Partial<{ overrides?: OverridesInput;}>; }
>something : any
>variables : { overrides?: OverridesInput | undefined; } & Partial<{ overrides?: OverridesInput | undefined; }>
overrides?: OverridesInput;
>overrides : OverridesInput | undefined
} & Partial<{
overrides?: OverridesInput;
>overrides : OverridesInput | undefined
}>} = { variables: { overrides: false } }; // Error
>{ variables: { overrides: false } } : { variables: { overrides: boolean; }; }
>variables : { overrides: boolean; }
>{ overrides: false } : { overrides: boolean; }
>overrides : boolean
>false : false
interface Unrelated { _?: any }
>_ : any
interface VariablesA { overrides?: OverridesInput; }
>overrides : OverridesInput | undefined
interface VariablesB { overrides?: OverridesInput; }
>overrides : OverridesInput | undefined
const foo2: Unrelated & { variables: VariablesA & VariablesB } = {
>foo2 : Unrelated & { variables: VariablesA & VariablesB; }
>variables : VariablesA & VariablesB
>{ variables: { overrides: false // Error }} : { variables: { overrides: boolean; }; }
variables: {
>variables : { overrides: boolean; }
>{ overrides: false // Error } : { overrides: boolean; }
overrides: false // Error
>overrides : boolean
>false : false
}
};
// Simplified repro from #52252
type T1 = {
>T1 : { primary: { __typename?: 'Feature';} & { colors: { light: number; dark: number; };}; }
primary: { __typename?: 'Feature' } & { colors: { light: number, dark: number } },
>primary : { __typename?: "Feature" | undefined; } & { colors: { light: number; dark: number;}; }
>__typename : "Feature" | undefined
>colors : { light: number; dark: number; }
>light : number
>dark : number
};
type T2 = {
>T2 : { primary: { __typename?: 'Feature';} & { colors: { light: number; };}; }
primary: { __typename?: 'Feature' } & { colors: { light: number } },
>primary : { __typename?: "Feature" | undefined; } & { colors: { light: number;}; }
>__typename : "Feature" | undefined
>colors : { light: number; }
>light : number
};
type Query = T1 & T2;
>Query : T1 & T2
const response: Query = {
>response : Query
>{ primary: { colors: { light: 1, dark: 3, }, },} : { primary: { colors: { light: number; dark: number; }; }; }
primary: {
>primary : { colors: { light: number; dark: number; }; }
>{ colors: { light: 1, dark: 3, }, } : { colors: { light: number; dark: number; }; }
colors: {
>colors : { light: number; dark: number; }
>{ light: 1, dark: 3, } : { light: number; dark: number; }
light: 1,
>light : number
>1 : 1
dark: 3,
>dark : number
>3 : 3
},
},
};