1
1
predicateSemantics.ts(7,16): error TS2871: This expression is always nullish.
2
2
predicateSemantics.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.
12
- predicateSemantics.ts(51,14): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish.
13
- predicateSemantics.ts(52,14): error TS2695: Left side of comma operator is unused and has no side effects.
14
- predicateSemantics.ts(52,14): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish.
15
- predicateSemantics.ts(70,1): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish.
16
- predicateSemantics.ts(71,1): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish.
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(28,13): error TS2871: This expression is always nullish.
6
+ predicateSemantics.ts(29,13): error TS2871: This expression is always nullish.
7
+ predicateSemantics.ts(30,13): error TS2872: This kind of expression is always truthy.
8
+ predicateSemantics.ts(31,13): error TS2872: This kind of expression is always truthy.
9
+ predicateSemantics.ts(32,13): error TS2871: This expression is always nullish.
10
+ predicateSemantics.ts(32,21): error TS2871: This expression is always nullish.
11
+ predicateSemantics.ts(33,13): error TS2871: This expression is always nullish.
12
+ predicateSemantics.ts(34,13): error TS2871: This expression is always nullish.
13
+ predicateSemantics.ts(34,22): error TS2871: This expression is always nullish.
14
+ predicateSemantics.ts(36,20): error TS2871: This expression is always nullish.
15
+ predicateSemantics.ts(37,20): error TS2871: This expression is always nullish.
16
+ predicateSemantics.ts(38,21): error TS2871: This expression is always nullish.
17
+ predicateSemantics.ts(39,21): error TS2871: This expression is always nullish.
18
+ predicateSemantics.ts(40,21): error TS2871: This expression is always nullish.
19
+ predicateSemantics.ts(40,29): error TS2871: This expression is always nullish.
20
+ predicateSemantics.ts(41,21): error TS2871: This expression is always nullish.
21
+ predicateSemantics.ts(42,20): error TS2881: This expression is never nullish.
22
+ predicateSemantics.ts(43,21): error TS2881: This expression is never nullish.
23
+ predicateSemantics.ts(45,13): error TS2871: This expression is always nullish.
24
+ predicateSemantics.ts(45,21): error TS2871: This expression is always nullish.
25
+ predicateSemantics.ts(45,29): error TS2871: This expression is always nullish.
26
+ predicateSemantics.ts(46,13): error TS2871: This expression is always nullish.
27
+ predicateSemantics.ts(46,21): error TS2881: This expression is never nullish.
28
+ predicateSemantics.ts(47,13): error TS2871: This expression is always nullish.
29
+ predicateSemantics.ts(47,22): error TS2881: This expression is never nullish.
30
+ predicateSemantics.ts(50,8): error TS2872: This kind of expression is always truthy.
31
+ predicateSemantics.ts(51,11): error TS2872: This kind of expression is always truthy.
32
+ predicateSemantics.ts(52,8): error TS2872: This kind of expression is always truthy.
33
+ predicateSemantics.ts(53,8): error TS2872: This kind of expression is always truthy.
34
+ predicateSemantics.ts(70,14): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish.
35
+ predicateSemantics.ts(71,14): error TS2695: Left side of comma operator is unused and has no side effects.
36
+ predicateSemantics.ts(71,14): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish.
37
+ predicateSemantics.ts(89,1): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish.
38
+ predicateSemantics.ts(90,1): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish.
17
39
18
40
19
- ==== predicateSemantics.ts (16 errors) ====
20
- declare let cond: any ;
41
+ ==== predicateSemantics.ts (38 errors) ====
42
+ declare let opt: number | undefined ;
21
43
22
44
// OK: One or other operand is possibly nullish
23
- const test1 = (cond ? undefined : 32) ?? "possibly reached";
45
+ const test1 = (opt ? undefined : 32) ?? "possibly reached";
24
46
25
47
// Not OK: Both operands nullish
26
- const test2 = (cond ? undefined : null) ?? "always reached";
27
- ~~~~~~~~~~~~~~~~~~~~~~~
48
+ const test2 = (opt ? undefined : null) ?? "always reached";
49
+ ~~~~~~~~~~~~~~~~~~~~~~
28
50
!!! error TS2871: This expression is always nullish.
29
51
30
52
// Not OK: Both operands non-nullish
31
- const test3 = (cond ? 132 : 17) ?? "unreachable";
32
- ~~~~~~~~~~~~~~~
53
+ const test3 = (opt ? 132 : 17) ?? "unreachable";
54
+ ~~~~~~~~~~~~~~
33
55
!!! error TS2869: Right operand of ?? is unreachable because the left operand is never nullish.
34
56
35
57
// Parens
36
- const test4 = (cond ? (undefined) : (17)) ?? 42;
58
+ const test4 = (opt ? (undefined) : (17)) ?? 42;
37
59
38
60
// Should be OK (special case)
39
61
if (!!true) {
@@ -46,21 +68,82 @@ predicateSemantics.ts(71,1): error TS2869: Right operand of ?? is unreachable be
46
68
while (true) { }
47
69
while (false) { }
48
70
49
- const p5 = {} ?? null;
50
- ~~
71
+ const p01 = {} ?? null;
72
+ ~~
51
73
!!! error TS2869: Right operand of ?? is unreachable because the left operand is never nullish.
52
- const p6 = 0 > 1 ?? null;
53
- ~~~~~
74
+ const p02 = 0 > 1 ?? null;
75
+ ~~~~~
54
76
!!! error TS2869: Right operand of ?? is unreachable because the left operand is never nullish.
55
- const p7 = null ?? null;
56
- ~~~~
77
+ const p03 = null ?? 1;
78
+ ~~~~
79
+ !!! error TS2871: This expression is always nullish.
80
+ const p04 = null ?? null;
81
+ ~~~~
57
82
!!! error TS2871: This expression is always nullish.
58
- const p8 = (class foo { }) && null;
59
- ~~~~~~~~~~~~~~~
83
+ const p05 = (class foo { }) && null;
84
+ ~~~~~~~~~~~~~~~
60
85
!!! error TS2872: This kind of expression is always truthy.
61
- const p9 = (class foo { }) || null;
62
- ~~~~~~~~~~~~~~~
86
+ const p06 = (class foo { }) || null;
87
+ ~~~~~~~~~~~~~~~
63
88
!!! error TS2872: This kind of expression is always truthy.
89
+ const p07 = null ?? null ?? null;
90
+ ~~~~
91
+ !!! error TS2871: This expression is always nullish.
92
+ ~~~~
93
+ !!! error TS2871: This expression is always nullish.
94
+ const p08 = null ?? opt ?? null;
95
+ ~~~~
96
+ !!! error TS2871: This expression is always nullish.
97
+ const p09 = null ?? (opt ? null : undefined) ?? null;
98
+ ~~~~
99
+ !!! error TS2871: This expression is always nullish.
100
+ ~~~~~~~~~~~~~~~~~~~~~~
101
+ !!! error TS2871: This expression is always nullish.
102
+
103
+ const p10 = opt ?? null ?? 1;
104
+ ~~~~
105
+ !!! error TS2871: This expression is always nullish.
106
+ const p11 = opt ?? null ?? null;
107
+ ~~~~
108
+ !!! error TS2871: This expression is always nullish.
109
+ const p12 = opt ?? (null ?? 1);
110
+ ~~~~
111
+ !!! error TS2871: This expression is always nullish.
112
+ const p13 = opt ?? (null ?? null);
113
+ ~~~~
114
+ !!! error TS2871: This expression is always nullish.
115
+ const p14 = opt ?? (null ?? null ?? null);
116
+ ~~~~
117
+ !!! error TS2871: This expression is always nullish.
118
+ ~~~~
119
+ !!! error TS2871: This expression is always nullish.
120
+ const p15 = opt ?? (opt ? null : undefined) ?? null;
121
+ ~~~~~~~~~~~~~~~~~~~~~~
122
+ !!! error TS2871: This expression is always nullish.
123
+ const p16 = opt ?? 1 ?? 2;
124
+ ~
125
+ !!! error TS2881: This expression is never nullish.
126
+ const p17 = opt ?? (opt ? 1 : 2) ?? 3;
127
+ ~~~~~~~~~~~
128
+ !!! error TS2881: This expression is never nullish.
129
+
130
+ const p21 = null ?? null ?? null ?? null;
131
+ ~~~~
132
+ !!! error TS2871: This expression is always nullish.
133
+ ~~~~
134
+ !!! error TS2871: This expression is always nullish.
135
+ ~~~~
136
+ !!! error TS2871: This expression is always nullish.
137
+ const p22 = null ?? 1 ?? 1;
138
+ ~~~~
139
+ !!! error TS2871: This expression is always nullish.
140
+ ~
141
+ !!! error TS2881: This expression is never nullish.
142
+ const p23 = null ?? (opt ? 1 : 2) ?? 1;
143
+ ~~~~
144
+ !!! error TS2871: This expression is always nullish.
145
+ ~~~~~~~~~~~
146
+ !!! error TS2881: This expression is never nullish.
64
147
65
148
// Outer expression tests
66
149
while ({} as any) { }
@@ -76,6 +159,8 @@ predicateSemantics.ts(71,1): error TS2869: Right operand of ?? is unreachable be
76
159
~~~~~~
77
160
!!! error TS2872: This kind of expression is always truthy.
78
161
162
+ declare let cond: any;
163
+
79
164
// Should be OK
80
165
console.log((cond || undefined) && 1 / cond);
81
166
0 commit comments