11predicateSemantics.ts(7,16): error TS2871: This expression is always nullish.
22predicateSemantics.ts(10,16): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish.
3- predicateSemantics.ts(26,12): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish.
4- predicateSemantics.ts(27,12): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish.
5- predicateSemantics.ts(28,12): error TS2871: This expression is always nullish.
6- predicateSemantics.ts(29,12): error TS2872: This kind of expression is always truthy.
7- predicateSemantics.ts(30,12): error TS2872: This kind of expression is always truthy.
8- predicateSemantics.ts(33,8): error TS2872: This kind of expression is always truthy.
9- predicateSemantics.ts(34,11): error TS2872: This kind of expression is always truthy.
10- predicateSemantics.ts(35,8): error TS2872: This kind of expression is always truthy.
11- predicateSemantics.ts(36,8): error TS2872: This kind of expression is always truthy.
3+ predicateSemantics.ts(26,13): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish.
4+ predicateSemantics.ts(27,13): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish.
5+ predicateSemantics.ts(30,13): error TS2872: This kind of expression is always truthy.
6+ predicateSemantics.ts(31,13): error TS2872: This kind of expression is always truthy.
7+ predicateSemantics.ts(32,21): error TS2871: This expression is always nullish.
8+ predicateSemantics.ts(34,20): error TS2871: This expression is always nullish.
9+ predicateSemantics.ts(35,20): error TS2871: This expression is always nullish.
10+ predicateSemantics.ts(38,29): error TS2871: This expression is always nullish.
11+ predicateSemantics.ts(40,22): error TS2871: This expression is always nullish.
12+ predicateSemantics.ts(41,21): error TS2871: This expression is always nullish.
13+ predicateSemantics.ts(41,29): error TS2871: This expression is always nullish.
14+ predicateSemantics.ts(42,21): error TS2874: This expression is never nullish.
15+ predicateSemantics.ts(43,22): error TS2874: This expression is never nullish.
16+ predicateSemantics.ts(46,8): error TS2872: This kind of expression is always truthy.
17+ predicateSemantics.ts(47,11): error TS2872: This kind of expression is always truthy.
18+ predicateSemantics.ts(48,8): error TS2872: This kind of expression is always truthy.
19+ predicateSemantics.ts(49,8): error TS2872: This kind of expression is always truthy.
1220
1321
14- ==== predicateSemantics.ts (11 errors) ====
15- declare let cond: any ;
22+ ==== predicateSemantics.ts (19 errors) ====
23+ declare let opt: number | undefined ;
1624
1725 // OK: One or other operand is possibly nullish
18- const test1 = (cond ? undefined : 32) ?? "possibly reached";
26+ const test1 = (opt ? undefined : 32) ?? "possibly reached";
1927
2028 // Not OK: Both operands nullish
21- const test2 = (cond ? undefined : null) ?? "always reached";
22- ~~~~~~~~~~~~~~~~~~~~~~~
29+ const test2 = (opt ? undefined : null) ?? "always reached";
30+ ~~~~~~~~~~~~~~~~~~~~~~
2331!!! error TS2871: This expression is always nullish.
2432
2533 // Not OK: Both operands non-nullish
26- const test3 = (cond ? 132 : 17) ?? "unreachable";
27- ~~~~~~~~~~~~~~~
34+ const test3 = (opt ? 132 : 17) ?? "unreachable";
35+ ~~~~~~~~~~~~~~
2836!!! error TS2869: Right operand of ?? is unreachable because the left operand is never nullish.
2937
3038 // Parens
31- const test4 = (cond ? (undefined) : (17)) ?? 42;
39+ const test4 = (opt ? (undefined) : (17)) ?? 42;
3240
3341 // Should be OK (special case)
3442 if (!!true) {
@@ -41,21 +49,50 @@ predicateSemantics.ts(36,8): error TS2872: This kind of expression is always tru
4149 while (true) { }
4250 while (false) { }
4351
44- const p5 = {} ?? null;
45- ~~
52+ const p01 = {} ?? null;
53+ ~~
4654!!! error TS2869: Right operand of ?? is unreachable because the left operand is never nullish.
47- const p6 = 0 > 1 ?? null;
48- ~~~~~
55+ const p02 = 0 > 1 ?? null;
56+ ~~~~~
4957!!! error TS2869: Right operand of ?? is unreachable because the left operand is never nullish.
50- const p7 = null ?? null;
51- ~~~~
52- !!! error TS2871: This expression is always nullish.
53- const p8 = (class foo { }) && null;
54- ~~~~~~~~~~~~~~~
58+ const p03 = null ?? 1;
59+ const p04 = null ?? null;
60+ const p05 = (class foo { }) && null;
61+ ~~~~~~~~~~~~~~~
5562!!! error TS2872: This kind of expression is always truthy.
56- const p9 = (class foo { }) || null;
57- ~~~~~~~~~~~~~~~
63+ const p06 = (class foo { }) || null;
64+ ~~~~~~~~~~~~~~~
5865!!! error TS2872: This kind of expression is always truthy.
66+ const p07 = null ?? null ?? null;
67+ ~~~~
68+ !!! error TS2871: This expression is always nullish.
69+
70+ const p10 = opt ?? null ?? 1;
71+ ~~~~
72+ !!! error TS2871: This expression is always nullish.
73+ const p11 = opt ?? null ?? null;
74+ ~~~~
75+ !!! error TS2871: This expression is always nullish.
76+ const p12 = opt ?? (null ?? 1);
77+ const p13 = opt ?? (null ?? null);
78+ const p14 = opt ?? (null ?? null ?? null);
79+ ~~~~
80+ !!! error TS2871: This expression is always nullish.
81+
82+ const p20 = null ?? (opt ? null : undefined) ?? null;
83+ ~~~~~~~~~~~~~~~~~~~~~~
84+ !!! error TS2871: This expression is always nullish.
85+ const p21 = null ?? null ?? null ?? null;
86+ ~~~~
87+ !!! error TS2871: This expression is always nullish.
88+ ~~~~
89+ !!! error TS2871: This expression is always nullish.
90+ const p22 = null ?? 1 ?? 1;
91+ ~
92+ !!! error TS2874: This expression is never nullish.
93+ const p23 = null ?? (opt ? 1 : 2) ?? 1;
94+ ~~~~~~~~~~~
95+ !!! error TS2874: This expression is never nullish.
5996
6097 // Outer expression tests
6198 while ({} as any) { }
@@ -71,6 +108,8 @@ predicateSemantics.ts(36,8): error TS2872: This kind of expression is always tru
71108 ~~~~~~
72109!!! error TS2872: This kind of expression is always truthy.
73110
111+ declare let cond: any;
112+
74113 // Should be OK
75114 console.log((cond || undefined) && 1 / cond);
76115
0 commit comments