@@ -36,24 +36,33 @@ tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(310,9): error TS
36
36
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(319,9): error TS2532: Object is possibly 'undefined'.
37
37
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(322,9): error TS2532: Object is possibly 'undefined'.
38
38
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(331,9): error TS2532: Object is possibly 'undefined'.
39
+ tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(334,9): error TS2532: Object is possibly 'undefined'.
40
+ tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(337,9): error TS2532: Object is possibly 'undefined'.
39
41
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(340,9): error TS2532: Object is possibly 'undefined'.
40
42
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(343,9): error TS2532: Object is possibly 'undefined'.
43
+ tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(346,9): error TS2532: Object is possibly 'undefined'.
44
+ tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(349,9): error TS2532: Object is possibly 'undefined'.
41
45
tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(352,9): error TS2532: Object is possibly 'undefined'.
42
- tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(391,9): error TS2532: Object is possibly 'undefined'.
43
- tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(394,9): error TS2532: Object is possibly 'undefined'.
44
- tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(403,9): error TS2532: Object is possibly 'undefined'.
45
- tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(406,9): error TS2532: Object is possibly 'undefined'.
46
- tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(415,9): error TS2532: Object is possibly 'undefined'.
47
- tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(424,9): error TS2532: Object is possibly 'undefined'.
48
- tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(427,9): error TS2532: Object is possibly 'undefined'.
49
- tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(436,9): error TS2532: Object is possibly 'undefined'.
50
- tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(471,13): error TS2532: Object is possibly 'undefined'.
51
- tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(474,13): error TS2532: Object is possibly 'undefined'.
52
- tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(488,13): error TS2532: Object is possibly 'undefined'.
53
- tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(491,13): error TS2532: Object is possibly 'undefined'.
46
+ tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(358,9): error TS2532: Object is possibly 'undefined'.
47
+ tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(367,9): error TS2532: Object is possibly 'undefined'.
48
+ tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(370,9): error TS2532: Object is possibly 'undefined'.
49
+ tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(379,9): error TS2532: Object is possibly 'undefined'.
50
+ tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(418,9): error TS2532: Object is possibly 'undefined'.
51
+ tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(421,9): error TS2532: Object is possibly 'undefined'.
52
+ tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(430,9): error TS2532: Object is possibly 'undefined'.
53
+ tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(433,9): error TS2532: Object is possibly 'undefined'.
54
+ tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(442,9): error TS2532: Object is possibly 'undefined'.
55
+ tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(451,9): error TS2532: Object is possibly 'undefined'.
56
+ tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(454,9): error TS2532: Object is possibly 'undefined'.
57
+ tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(463,9): error TS2532: Object is possibly 'undefined'.
58
+ tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(498,13): error TS2532: Object is possibly 'undefined'.
59
+ tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(501,13): error TS2532: Object is possibly 'undefined'.
60
+ tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(515,13): error TS2532: Object is possibly 'undefined'.
61
+ tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(518,13): error TS2532: Object is possibly 'undefined'.
62
+ tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(567,21): error TS2532: Object is possibly 'undefined'.
54
63
55
64
56
- ==== tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts (53 errors) ====
65
+ ==== tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts (62 errors) ====
57
66
// assignments in shortcutting chain
58
67
declare const o: undefined | {
59
68
[key: string]: any;
@@ -456,6 +465,49 @@ tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(491,13): error T
456
465
}
457
466
}
458
467
468
+ function f15a(o: Thing | undefined, value: unknown) {
469
+ if (o?.foo === value) {
470
+ o.foo; // Error
471
+ ~
472
+ !!! error TS2532: Object is possibly 'undefined'.
473
+ }
474
+ else {
475
+ o.foo; // Error
476
+ ~
477
+ !!! error TS2532: Object is possibly 'undefined'.
478
+ }
479
+ if (o?.foo !== value) {
480
+ o.foo; // Error
481
+ ~
482
+ !!! error TS2532: Object is possibly 'undefined'.
483
+ }
484
+ else {
485
+ o.foo; // Error
486
+ ~
487
+ !!! error TS2532: Object is possibly 'undefined'.
488
+ }
489
+ if (o?.foo == value) {
490
+ o.foo; // Error
491
+ ~
492
+ !!! error TS2532: Object is possibly 'undefined'.
493
+ }
494
+ else {
495
+ o.foo; // Error
496
+ ~
497
+ !!! error TS2532: Object is possibly 'undefined'.
498
+ }
499
+ if (o?.foo != value) {
500
+ o.foo; // Error
501
+ ~
502
+ !!! error TS2532: Object is possibly 'undefined'.
503
+ }
504
+ else {
505
+ o.foo; // Error
506
+ ~
507
+ !!! error TS2532: Object is possibly 'undefined'.
508
+ }
509
+ }
510
+
459
511
function f16(o: Thing | undefined) {
460
512
if (o?.foo === undefined) {
461
513
o.foo; // Error
@@ -687,4 +739,29 @@ tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(491,13): error T
687
739
}
688
740
return f.geometry.coordinates;
689
741
}
742
+
743
+ // Repro from #35842
744
+
745
+ interface SomeObject {
746
+ someProperty: unknown;
747
+ }
748
+
749
+ let lastSomeProperty: unknown | undefined;
750
+
751
+ function someFunction(someOptionalObject: SomeObject | undefined): void {
752
+ if (someOptionalObject?.someProperty !== lastSomeProperty) {
753
+ console.log(someOptionalObject);
754
+ console.log(someOptionalObject.someProperty); // Error
755
+ ~~~~~~~~~~~~~~~~~~
756
+ !!! error TS2532: Object is possibly 'undefined'.
757
+ lastSomeProperty = someOptionalObject?.someProperty;
758
+ }
759
+ }
760
+
761
+ const someObject: SomeObject = {
762
+ someProperty: 42
763
+ };
764
+
765
+ someFunction(someObject);
766
+ someFunction(undefined);
690
767
0 commit comments