File: controlFlowOptionalChain.errors.txt

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 (793 lines) | stat: -rw-r--r-- 24,878 bytes parent folder | download
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(10,1): error TS2454: Variable 'a' is used before being assigned.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(14,1): error TS2454: Variable 'b' is used before being assigned.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(18,1): error TS2454: Variable 'c' is used before being assigned.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(22,1): error TS2454: Variable 'd' is used before being assigned.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(35,5): error TS2722: Cannot invoke an object which is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(39,1): error TS2722: Cannot invoke an object which is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(52,5): error TS18048: 'o2' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(57,1): error TS18048: 'o2' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(68,5): error TS18048: 'o3' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(72,1): error TS18048: 'o3' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(83,5): error TS18048: 'o4.x' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(87,1): error TS18048: 'o4.x' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(104,5): error TS18048: 'o5.x' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(105,5): error TS18048: 'o5.x' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(105,5): error TS18048: 'o5.x.y.z' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(111,1): error TS18048: 'o5.x' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(112,1): error TS18048: 'o5.x' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(112,1): error TS18048: 'o5.x.y.z' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(130,5): error TS18048: 'o6' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(134,1): error TS18048: 'o6' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(208,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(211,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(214,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(217,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(220,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(223,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(238,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(241,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(244,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(271,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(274,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(277,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(307,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(310,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(319,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(322,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(331,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(334,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(337,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(340,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(343,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(346,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(349,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(352,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(358,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(367,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(370,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(379,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(418,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(421,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(430,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(433,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(442,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(451,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(454,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(463,9): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(498,13): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(501,13): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(515,13): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(518,13): error TS18048: 'o' is possibly 'undefined'.
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(567,21): error TS18048: 'someOptionalObject' is possibly 'undefined'.


==== tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts (61 errors) ====
    // assignments in shortcutting chain
    declare const o: undefined | {
        [key: string]: any;
        [key: number]: any;
        (...args: any[]): any;
    };
    
    let a: number;
    o?.[a = 1];
    a.toString();
    ~
!!! error TS2454: Variable 'a' is used before being assigned.
    
    let b: number;
    o?.x[b = 1];
    b.toString();
    ~
!!! error TS2454: Variable 'b' is used before being assigned.
    
    let c: number;
    o?.(c = 1)
    c.toString();
    ~
!!! error TS2454: Variable 'c' is used before being assigned.
    
    let d: number;
    o?.x(d = 1);
    d.toString();
    ~
!!! error TS2454: Variable 'd' is used before being assigned.
    
    // type predicates
    declare const f: undefined | ((x: any) => x is number);
    declare const x: string | number;
    if (f?.(x)) {
        x; // number
        f; // (x: any) => x is number
        f(x);
    }
    else {
        x;
        f;
        f(x);
        ~
!!! error TS2722: Cannot invoke an object which is possibly 'undefined'.
    }
    x;
    f;
    f(x);
    ~
!!! error TS2722: Cannot invoke an object which is possibly 'undefined'.
    
    declare const o2: { f(x: any): x is number; } | undefined;
    if (o2?.f(x)) {
        x; // number
        o2.f; // (x: any) => x is number
        o2?.f;
        o2?.f(x);
    }
    else {
        x;
        o2;
        o2?.f;
        o2.f;
        ~~
!!! error TS18048: 'o2' is possibly 'undefined'.
    }
    x;
    o2;
    o2?.f;
    o2.f;
    ~~
!!! error TS18048: 'o2' is possibly 'undefined'.
    
    declare const o3: { x: 1, y: string } | { x: 2, y: number } | undefined;
    if (o3?.x === 1) {
        o3;
        o3.x;
        o3?.x;
    }
    else {
        o3;
        o3?.x;
        o3.x;
        ~~
!!! error TS18048: 'o3' is possibly 'undefined'.
    }
    o3;
    o3?.x;
    o3.x;
    ~~
!!! error TS18048: 'o3' is possibly 'undefined'.
    
    declare const o4: { x?: { y: boolean } };
    if (o4.x?.y) {
        o4.x; // { y: boolean }
        o4.x.y; // true
        o4.x?.y; // true
    }
    else {
        o4.x;
        o4.x?.y;
        o4.x.y;
        ~~~~
!!! error TS18048: 'o4.x' is possibly 'undefined'.
    }
    o4.x;
    o4.x?.y;
    o4.x.y;
    ~~~~
!!! error TS18048: 'o4.x' is possibly 'undefined'.
    
    declare const o5: { x?: { y: { z?: { w: boolean } } } };
    if (o5.x?.y.z?.w) {
        o5.x;
        o5.x.y;
        o5.x.y.z;
        o5.x.y.z.w; // true
        o5.x.y.z?.w; // true
        o5.x?.y.z.w; // true
        o5.x?.y.z?.w; // true
    }
    else {
        o5.x;
        o5.x?.y;
        o5.x?.y.z;
        o5.x?.y.z?.w;
        o5.x.y;
        ~~~~
!!! error TS18048: 'o5.x' is possibly 'undefined'.
        o5.x.y.z.w;
        ~~~~
!!! error TS18048: 'o5.x' is possibly 'undefined'.
        ~~~~~~~~
!!! error TS18048: 'o5.x.y.z' is possibly 'undefined'.
    }
    o5.x;
    o5.x?.y;
    o5.x?.y.z;
    o5.x?.y.z?.w;
    o5.x.y;
    ~~~~
!!! error TS18048: 'o5.x' is possibly 'undefined'.
    o5.x.y.z.w;
    ~~~~
!!! error TS18048: 'o5.x' is possibly 'undefined'.
    ~~~~~~~~
!!! error TS18048: 'o5.x.y.z' is possibly 'undefined'.
    
    interface Base {
        f(): this is Derived;
    }
    
    interface Derived extends Base {
        x: number;
    }
    
    declare const o6: Base | undefined;
    if (o6?.f()) {
        o6; // Derived
        o6.f;
    }
    else {
        o6;
        o6?.f;
        o6.f;
        ~~
!!! error TS18048: 'o6' is possibly 'undefined'.
    }
    o6;
    o6?.f;
    o6.f;
    ~~
!!! error TS18048: 'o6' is possibly 'undefined'.
    
    // asserts
    declare const isDefined: <T>(value: T) => asserts value is NonNullable<T>;
    declare const isString: (value: unknown) => asserts value is string;
    declare const maybeIsString: undefined | ((value: unknown) => asserts value is string);
    declare const maybeNever: undefined | (() => never);
    
    function f01(x: unknown) {
        if (!!true) {
            isString?.(x);
            x;
        }
        if (!!true) {
            maybeIsString?.(x);
            x;
        }
        if (!!true) {
            isDefined(maybeIsString);
            maybeIsString?.(x);
            x;
        }
        if (!!true) {
            maybeNever?.();
            x;
        }
    }
    
    type Thing = { foo: string | number, bar(): number, baz: object };
    
    function f10(o: Thing | undefined, value: number) {
        if (o?.foo === value) {
            o.foo;
        }
        if (o?.["foo"] === value) {
            o["foo"];
        }
        if (o?.bar() === value) {
            o.bar;
        }
        if (o?.foo == value) {
            o.foo;
        }
        if (o?.["foo"] == value) {
            o["foo"];
        }
        if (o?.bar() == value) {
            o.bar;
        }
    }
    
    function f11(o: Thing | null, value: number) {
        if (o?.foo === value) {
            o.foo;
        }
        if (o?.["foo"] === value) {
            o["foo"];
        }
        if (o?.bar() === value) {
            o.bar;
        }
        if (o?.foo == value) {
            o.foo;
        }
        if (o?.["foo"] == value) {
            o["foo"];
        }
        if (o?.bar() == value) {
            o.bar;
        }
    }
    
    function f12(o: Thing | undefined, value: number | undefined) {
        if (o?.foo === value) {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        if (o?.["foo"] === value) {
            o["foo"];  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        if (o?.bar() === value) {
            o.bar;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        if (o?.foo == value) {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        if (o?.["foo"] == value) {
            o["foo"];  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        if (o?.bar() == value) {
            o.bar;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
    }
    
    function f12a(o: Thing | undefined, value: number | null) {
        if (o?.foo === value) {
            o.foo;
        }
        if (o?.["foo"] === value) {
            o["foo"];
        }
        if (o?.bar() === value) {
            o.bar;
        }
        if (o?.foo == value) {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        if (o?.["foo"] == value) {
            o["foo"];  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        if (o?.bar() == value) {
            o.bar;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
    }
    
    function f13(o: Thing | undefined) {
        if (o?.foo !== undefined) {
            o.foo;
        }
        if (o?.["foo"] !== undefined) {
            o["foo"];
        }
        if (o?.bar() !== undefined) {
            o.bar;
        }
        if (o?.foo != undefined) {
            o.foo;
        }
        if (o?.["foo"] != undefined) {
            o["foo"];
        }
        if (o?.bar() != undefined) {
            o.bar;
        }
    }
    
    function f13a(o: Thing | undefined) {
        if (o?.foo !== null) {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        if (o?.["foo"] !== null) {
            o["foo"];  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        if (o?.bar() !== null) {
            o.bar;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        if (o?.foo != null) {
            o.foo;
        }
        if (o?.["foo"] != null) {
            o["foo"];
        }
        if (o?.bar() != null) {
            o.bar;
        }
    }
    
    function f14(o: Thing | null) {
        if (o?.foo !== undefined) {
            o.foo;
        }
        if (o?.["foo"] !== undefined) {
            o["foo"];
        }
        if (o?.bar() !== undefined) {
            o.bar;
        }
    }
    
    function f15(o: Thing | undefined, value: number) {
        if (o?.foo === value) {
            o.foo;
        }
        else {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        if (o?.foo !== value) {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        else {
            o.foo;
        }
        if (o?.foo == value) {
            o.foo;
        }
        else {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        if (o?.foo != value) {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        else {
            o.foo;
        }
    }
    
    function f15a(o: Thing | undefined, value: unknown) {
        if (o?.foo === value) {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        else {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        if (o?.foo !== value) {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        else {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        if (o?.foo == value) {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        else {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        if (o?.foo != value) {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        else {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
    }
    
    function f16(o: Thing | undefined) {
        if (o?.foo === undefined) {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        else {
            o.foo;
        }
        if (o?.foo !== undefined) {
            o.foo;
        }
        else {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        if (o?.foo == undefined) {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        else {
            o.foo;
        }
        if (o?.foo != undefined) {
            o.foo;
        }
        else {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
    }
    
    function f20(o: Thing | undefined) {
        if (typeof o?.foo === "number") {
            o.foo;
        }
        if (typeof o?.["foo"] === "number") {
            o["foo"];
        }
        if (typeof o?.bar() === "number") {
            o.bar;
        }
        if (o?.baz instanceof Error) {
            o.baz;
        }
    }
    
    function f21(o: Thing | null) {
        if (typeof o?.foo === "number") {
            o.foo;
        }
        if (typeof o?.["foo"] === "number") {
            o["foo"];
        }
        if (typeof o?.bar() === "number") {
            o.bar;
        }
        if (o?.baz instanceof Error) {
            o.baz;
        }
    }
    
    function f22(o: Thing | undefined) {
        if (typeof o?.foo === "number") {
            o.foo;
        }
        else {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        if (typeof o?.foo !== "number") {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        else {
            o.foo;
        }
        if (typeof o?.foo == "number") {
            o.foo;
        }
        else {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        if (typeof o?.foo != "number") {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        else {
            o.foo;
        }
    }
    
    function f23(o: Thing | undefined) {
        if (typeof o?.foo === "undefined") {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        else {
            o.foo;
        }
        if (typeof o?.foo !== "undefined") {
            o.foo;
        }
        else {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        if (typeof o?.foo == "undefined") {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
        else {
            o.foo;
        }
        if (typeof o?.foo != "undefined") {
            o.foo;
        }
        else {
            o.foo;  // Error
            ~
!!! error TS18048: 'o' is possibly 'undefined'.
        }
    }
    
    declare function assert(x: unknown): asserts x;
    declare function assertNonNull<T>(x: T): asserts x is NonNullable<T>;
    
    function f30(o: Thing | undefined) {
        if (!!true) {
            assert(o?.foo);
            o.foo;
        }
        if (!!true) {
            assert(o?.foo === 42);
            o.foo;
        }
        if (!!true) {
            assert(typeof o?.foo === "number");
            o.foo;
        }
        if (!!true) {
            assertNonNull(o?.foo);
            o.foo;
        }
    }
    
    function f40(o: Thing | undefined) {
        switch (o?.foo) {
            case "abc":
                o.foo;
                break;
            case 42:
                o.foo;
                break;
            case undefined:
                o.foo;  // Error
                ~
!!! error TS18048: 'o' is possibly 'undefined'.
                break;
            default:
                o.foo;  // Error
                ~
!!! error TS18048: 'o' is possibly 'undefined'.
                break;
        }
    }
    
    function f41(o: Thing | undefined) {
        switch (typeof o?.foo) {
            case "string":
                o.foo;
                break;
            case "number":
                o.foo;
                break;
            case "undefined":
                o.foo;  // Error
                ~
!!! error TS18048: 'o' is possibly 'undefined'.
                break;
            default:
                o.foo;  // Error
                ~
!!! error TS18048: 'o' is possibly 'undefined'.
                break;
        }
    }
    
    // Repros from #34570
    
    type Shape =
        | { type: 'rectangle', width: number, height: number }
        | { type: 'circle', radius: number }
    
    function getArea(shape?: Shape) {
        switch (shape?.type) {
            case 'circle':
                return Math.PI * shape.radius ** 2
            case 'rectangle':
                return shape.width * shape.height
            default:
                return 0
        }
    }
    
    type Feature = {
      id: string;
      geometry?: {
        type: string;
        coordinates: number[];
      };
    };
    
    
    function extractCoordinates(f: Feature): number[] {
        if (f.geometry?.type !== 'test') {
            return [];
        }
        return f.geometry.coordinates;
    }
    
    // Repro from #35842
    
    interface SomeObject {
        someProperty: unknown;
    }
    
    let lastSomeProperty: unknown | undefined;
    
    function someFunction(someOptionalObject: SomeObject | undefined): void {
        if (someOptionalObject?.someProperty !== lastSomeProperty) {
            console.log(someOptionalObject);
            console.log(someOptionalObject.someProperty);  // Error
                        ~~~~~~~~~~~~~~~~~~
!!! error TS18048: 'someOptionalObject' is possibly 'undefined'.
            lastSomeProperty = someOptionalObject?.someProperty;
        }
    }
    
    const someObject: SomeObject = {
        someProperty: 42
    };
    
    someFunction(someObject);
    someFunction(undefined);
    
    // Repro from #35970
    
    let i = 0;
    declare const arr: { tag: ("left" | "right") }[];
    
    while (arr[i]?.tag === "left") {
        i += 1;
        if (arr[i]?.tag === "right") {
            console.log("I should ALSO be reachable");
        }
    }
    
    
    // Repro from #51941
    
    type Test5 = {
      main?: {
        childs: Record<string, Test5>;
      };
    };
    
    function f50(obj: Test5) {
       for (const key in obj.main?.childs) {
          if (obj.main.childs[key] === obj) {
            return obj;
          }
       }
       return null;
    }