@@ -253,6 +253,26 @@ function test<T>(a: T) {
253
253
const t16 = undefined !== a;
254
254
}
255
255
` ,
256
+ `
257
+ function foo<T extends object>(arg: T, key: keyof T): void {
258
+ const t1 = arg[key] == null;
259
+ const t2 = null == arg[key];
260
+ const t3 = arg[key] != null;
261
+ const t4 = null != arg[key];
262
+ const t5 = arg[key] == undefined;
263
+ const t6 = undefined == arg[key];
264
+ const t7 = arg[key] != undefined;
265
+ const t8 = undefined != arg[key];
266
+ const t9 = arg[key] === null;
267
+ const t10 = null === arg[key];
268
+ const t11 = arg[key] !== null;
269
+ const t12 = null !== arg[key];
270
+ const t13 = arg[key] === undefined;
271
+ const t14 = undefined === arg[key];
272
+ const t15 = arg[key] !== undefined;
273
+ const t16 = undefined !== arg[key];
274
+ }
275
+ ` ,
256
276
257
277
// Predicate functions
258
278
`
@@ -317,6 +337,11 @@ function test<T>(a: T) {
317
337
`
318
338
function test<T extends string | null>(a: T) {
319
339
return a ?? 'default';
340
+ }
341
+ ` ,
342
+ `
343
+ function foo<T extends object>(arg: T, key: keyof T): void {
344
+ arg[key] ?? 'default';
320
345
}
321
346
` ,
322
347
// Indexing cases
@@ -740,6 +765,13 @@ foo ||= 1;
740
765
`
741
766
declare let foo: number;
742
767
foo &&= 1;
768
+ ` ,
769
+ `
770
+ function foo<T extends object>(arg: T, key: keyof T): void {
771
+ arg[key] ??= 'default';
772
+ arg[key] ||= 'default';
773
+ arg[key] &&= 'default';
774
+ }
743
775
` ,
744
776
// https://github.com/typescript-eslint/typescript-eslint/issues/6264
745
777
`
@@ -1084,7 +1116,14 @@ function test(a: never) {
1084
1116
` ,
1085
1117
errors : [ ruleError ( 3 , 10 , 'never' ) ] ,
1086
1118
} ,
1087
-
1119
+ {
1120
+ code : `
1121
+ function test<T extends { foo: number }, K extends 'foo'>(num: T[K]) {
1122
+ num ?? 'default';
1123
+ }
1124
+ ` ,
1125
+ errors : [ ruleError ( 3 , 3 , 'neverNullish' ) ] ,
1126
+ } ,
1088
1127
// Predicate functions
1089
1128
{
1090
1129
code : `
0 commit comments