File: narrowingOfQualifiedNames.types

package info (click to toggle)
node-typescript 5.0.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 459,140 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (332 lines) | stat: -rw-r--r-- 9,612 bytes parent folder | download | duplicates (3)
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
=== tests/cases/compiler/narrowingOfQualifiedNames.ts ===
// Repro from #43411

interface IProperties {
    foo?: {
>foo : { aaa: string; bbb: string; } | undefined

        aaa: string
>aaa : string

        bbb: string
>bbb : string
    }
}

function init(properties: IProperties) {
>init : (properties: IProperties) => void
>properties : IProperties

    if (properties.foo) {
>properties.foo : { aaa: string; bbb: string; } | undefined
>properties : IProperties
>foo : { aaa: string; bbb: string; } | undefined

        type FooOK = typeof properties.foo;
>FooOK : { aaa: string; bbb: string; }
>properties.foo : { aaa: string; bbb: string; }
>properties : IProperties
>foo : { aaa: string; bbb: string; }

        properties.foo; // type is { aaa: string; bbb: string; }
>properties.foo : { aaa: string; bbb: string; }
>properties : IProperties
>foo : { aaa: string; bbb: string; }

        for (const x of [1, 2, 3]) {
>x : number
>[1, 2, 3] : number[]
>1 : 1
>2 : 2
>3 : 3

          properties.foo; // type is { aaa: string; bbb: string; }
>properties.foo : { aaa: string; bbb: string; }
>properties : IProperties
>foo : { aaa: string; bbb: string; }

          type FooOrUndefined = typeof properties.foo; // type should be { aaa: string; bbb: string; }
>FooOrUndefined : { aaa: string; bbb: string; }
>properties.foo : { aaa: string; bbb: string; }
>properties : IProperties
>foo : { aaa: string; bbb: string; }
        }
    }
}

interface DeepOptional {
    a?: {
>a : { b?: { c?: string | undefined; } | undefined; } | undefined

        b?: {
>b : { c?: string | undefined; } | undefined

            c?: string
>c : string | undefined
        }
    }
}

function init2(foo: DeepOptional) {
>init2 : (foo: DeepOptional) => void
>foo : DeepOptional

    if (foo.a) {
>foo.a : { b?: { c?: string | undefined; } | undefined; } | undefined
>foo : DeepOptional
>a : { b?: { c?: string | undefined; } | undefined; } | undefined

        type A = typeof foo.a;
>A : { b?: { c?: string | undefined; } | undefined; }
>foo.a : { b?: { c?: string | undefined; } | undefined; }
>foo : DeepOptional
>a : { b?: { c?: string | undefined; } | undefined; }

        type B = typeof foo.a.b;
>B : { c?: string | undefined; } | undefined
>foo.a.b : { c?: string | undefined; } | undefined
>foo.a : { b?: { c?: string | undefined; } | undefined; }
>foo : DeepOptional
>a : { b?: { c?: string | undefined; } | undefined; }
>b : { c?: string | undefined; } | undefined

        type C = typeof foo.a.b.c;
>C : string | undefined
>foo.a.b.c : string | undefined
>foo.a.b : { c?: string | undefined; } | undefined
>foo.a : { b?: { c?: string | undefined; } | undefined; }
>foo : DeepOptional
>a : { b?: { c?: string | undefined; } | undefined; }
>b : { c?: string | undefined; } | undefined
>c : string | undefined

        for(const _ of [1]) {
>_ : number
>[1] : number[]
>1 : 1

            type A = typeof foo.a;
>A : { b?: { c?: string | undefined; } | undefined; }
>foo.a : { b?: { c?: string | undefined; } | undefined; }
>foo : DeepOptional
>a : { b?: { c?: string | undefined; } | undefined; }

            type B = typeof foo.a.b;
>B : { c?: string | undefined; } | undefined
>foo.a.b : { c?: string | undefined; } | undefined
>foo.a : { b?: { c?: string | undefined; } | undefined; }
>foo : DeepOptional
>a : { b?: { c?: string | undefined; } | undefined; }
>b : { c?: string | undefined; } | undefined

            type C = typeof foo.a.b.c;
>C : string | undefined
>foo.a.b.c : string | undefined
>foo.a.b : { c?: string | undefined; } | undefined
>foo.a : { b?: { c?: string | undefined; } | undefined; }
>foo : DeepOptional
>a : { b?: { c?: string | undefined; } | undefined; }
>b : { c?: string | undefined; } | undefined
>c : string | undefined

            if (foo.a.b) {
>foo.a.b : { c?: string | undefined; } | undefined
>foo.a : { b?: { c?: string | undefined; } | undefined; }
>foo : DeepOptional
>a : { b?: { c?: string | undefined; } | undefined; }
>b : { c?: string | undefined; } | undefined

                type A = typeof foo.a;
>A : { b?: { c?: string | undefined; } | undefined; }
>foo.a : { b?: { c?: string | undefined; } | undefined; }
>foo : DeepOptional
>a : { b?: { c?: string | undefined; } | undefined; }

                type B = typeof foo.a.b;
>B : { c?: string | undefined; }
>foo.a.b : { c?: string | undefined; }
>foo.a : { b?: { c?: string | undefined; } | undefined; }
>foo : DeepOptional
>a : { b?: { c?: string | undefined; } | undefined; }
>b : { c?: string | undefined; }

                type C = typeof foo.a.b.c;
>C : string | undefined
>foo.a.b.c : string | undefined
>foo.a.b : { c?: string | undefined; }
>foo.a : { b?: { c?: string | undefined; } | undefined; }
>foo : DeepOptional
>a : { b?: { c?: string | undefined; } | undefined; }
>b : { c?: string | undefined; }
>c : string | undefined

                for(const _ of [1]) {
>_ : number
>[1] : number[]
>1 : 1

                    type A = typeof foo.a;
>A : { b?: { c?: string | undefined; } | undefined; }
>foo.a : { b?: { c?: string | undefined; } | undefined; }
>foo : DeepOptional
>a : { b?: { c?: string | undefined; } | undefined; }

                    type B = typeof foo.a.b;
>B : { c?: string | undefined; }
>foo.a.b : { c?: string | undefined; }
>foo.a : { b?: { c?: string | undefined; } | undefined; }
>foo : DeepOptional
>a : { b?: { c?: string | undefined; } | undefined; }
>b : { c?: string | undefined; }

                    type C = typeof foo.a.b.c;
>C : string | undefined
>foo.a.b.c : string | undefined
>foo.a.b : { c?: string | undefined; }
>foo.a : { b?: { c?: string | undefined; } | undefined; }
>foo : DeepOptional
>a : { b?: { c?: string | undefined; } | undefined; }
>b : { c?: string | undefined; }
>c : string | undefined

                    if (foo.a.b.c) {
>foo.a.b.c : string | undefined
>foo.a.b : { c?: string | undefined; }
>foo.a : { b?: { c?: string | undefined; } | undefined; }
>foo : DeepOptional
>a : { b?: { c?: string | undefined; } | undefined; }
>b : { c?: string | undefined; }
>c : string | undefined

                        type A = typeof foo.a;
>A : { b?: { c?: string | undefined; } | undefined; }
>foo.a : { b?: { c?: string | undefined; } | undefined; }
>foo : DeepOptional
>a : { b?: { c?: string | undefined; } | undefined; }

                        type B = typeof foo.a.b;
>B : { c?: string | undefined; }
>foo.a.b : { c?: string | undefined; }
>foo.a : { b?: { c?: string | undefined; } | undefined; }
>foo : DeepOptional
>a : { b?: { c?: string | undefined; } | undefined; }
>b : { c?: string | undefined; }

                        type C = typeof foo.a.b.c;
>C : string
>foo.a.b.c : string
>foo.a.b : { c?: string | undefined; }
>foo.a : { b?: { c?: string | undefined; } | undefined; }
>foo : DeepOptional
>a : { b?: { c?: string | undefined; } | undefined; }
>b : { c?: string | undefined; }
>c : string

                        for(const _ of [1]) {
>_ : number
>[1] : number[]
>1 : 1

                            type A = typeof foo.a;
>A : { b?: { c?: string | undefined; } | undefined; }
>foo.a : { b?: { c?: string | undefined; } | undefined; }
>foo : DeepOptional
>a : { b?: { c?: string | undefined; } | undefined; }

                            type B = typeof foo.a.b;
>B : { c?: string | undefined; }
>foo.a.b : { c?: string | undefined; }
>foo.a : { b?: { c?: string | undefined; } | undefined; }
>foo : DeepOptional
>a : { b?: { c?: string | undefined; } | undefined; }
>b : { c?: string | undefined; }

                            type C = typeof foo.a.b.c;
>C : string
>foo.a.b.c : string
>foo.a.b : { c?: string | undefined; }
>foo.a : { b?: { c?: string | undefined; } | undefined; }
>foo : DeepOptional
>a : { b?: { c?: string | undefined; } | undefined; }
>b : { c?: string | undefined; }
>c : string
                        }
                    }
                }
            }
        }
    }
}

// Repro from #48289

type Fish = { type: 'fish', hasFins: true }
>Fish : { type: 'fish'; hasFins: true; }
>type : "fish"
>hasFins : true
>true : true

type Dog = { type: 'dog', saysWoof: true }
>Dog : { type: 'dog'; saysWoof: true; }
>type : "dog"
>saysWoof : true
>true : true

type Pet = Fish | Dog;
>Pet : Fish | Dog

function handleDogBroken<PetType extends Pet>(pet: PetType) {
>handleDogBroken : <PetType extends Pet>(pet: PetType) => void
>pet : PetType

    if(pet.type === 'dog') {
>pet.type === 'dog' : boolean
>pet.type : "fish" | "dog"
>pet : Pet
>type : "fish" | "dog"
>'dog' : "dog"

        const _okay1 = pet.saysWoof;
>_okay1 : true
>pet.saysWoof : true
>pet : Dog
>saysWoof : true

        const _okay2: typeof pet.saysWoof = pet.saysWoof;
>_okay2 : true
>pet.saysWoof : true
>pet : Dog
>saysWoof : true
>pet.saysWoof : true
>pet : Dog
>saysWoof : true
    }
}

function handleDogWorking(pet: Pet) {
>handleDogWorking : (pet: Pet) => void
>pet : Pet

    if(pet.type === 'dog') {
>pet.type === 'dog' : boolean
>pet.type : "fish" | "dog"
>pet : Pet
>type : "fish" | "dog"
>'dog' : "dog"

        const _okay1 = pet.saysWoof;
>_okay1 : true
>pet.saysWoof : true
>pet : Dog
>saysWoof : true

        const _okay2: typeof pet.saysWoof = pet.saysWoof;
>_okay2 : true
>pet.saysWoof : true
>pet : Dog
>saysWoof : true
>pet.saysWoof : true
>pet : Dog
>saysWoof : true
    }
}