@@ -141,23 +141,50 @@ function once<ET, T extends EventEmitter<ET>>(emittingObject: T, eventName: keyo
141
141
emittingObject . off ( eventName as typeof eventName , 0 ) ;
142
142
}
143
143
144
- // In an element access obj[x ], we consider obj to be in a constraint position, except when obj is of
145
- // a generic type without a nullable constraint and x is a generic type. This is because when both obj
146
- // and x are of generic types T and K, we want the resulting type to be T[K].
144
+ // In an element access obj[key ], we consider obj to be in a constraint position, except when
145
+ // obj and key both have generic types. When obj and key are of generic types T and K, we want
146
+ // the resulting type to be T[K].
147
147
148
148
function fx1 < T , K extends keyof T > ( obj : T , key : K ) {
149
149
const x1 = obj [ key ] ;
150
150
const x2 = obj && obj [ key ] ;
151
+ const x3 = obj ?. [ key ] ;
151
152
}
152
153
153
154
function fx2 < T extends Record < keyof T , string > , K extends keyof T > ( obj : T , key : K ) {
154
155
const x1 = obj [ key ] ;
155
156
const x2 = obj && obj [ key ] ;
157
+ const x3 = obj ?. [ key ] ;
156
158
}
157
159
158
160
function fx3 < T extends Record < keyof T , string > | undefined, K extends keyof T> ( obj : T , key : K ) {
161
+ const x1 = obj [ key ] ;
162
+ const x2 = obj && obj [ key ] ;
163
+ const x3 = obj ?. [ key ] ;
164
+ }
165
+
166
+ function fx4 < T extends unknown , K extends keyof T > (obj: T, key: K) {
167
+ const x1 = obj [ key ] ;
168
+ const x2 = obj && obj [ key ] ;
169
+ const x3 = obj ?. [ key ] ;
170
+ }
171
+
172
+ function fx5< T extends { } | null | undefined , K extends keyof T > (obj: T, key: K) {
173
+ const x1 = obj [ key ] ;
174
+ const x2 = obj && obj [ key ] ;
175
+ const x3 = obj ?. [ key ] ;
176
+ }
177
+
178
+ function fx6< T , K extends keyof T > (obj: T | null | undefined, key: K) {
159
179
const x1 = obj [ key ] ; // Error
160
180
const x2 = obj && obj [ key ] ;
181
+ const x3 = obj ?. [ key ] ;
182
+ }
183
+
184
+ function fx7< T , K extends keyof T > (obj: { x : T } | null | undefined, key: K) {
185
+ const x1 = obj . x [ key ] ; // Error
186
+ const x2 = obj && obj . x [ key ] ;
187
+ const x3 = obj ?. x [ key ] ;
161
188
}
162
189
163
190
// Repro from #44166
@@ -167,8 +194,8 @@ class TableBaseEnum<
167
194
InternalSpec extends Record< keyof PublicSpec , any > | undefined = undefined> {
168
195
m ( ) {
169
196
let iSpec = null ! as InternalSpec ;
170
- iSpec [ null ! as keyof InternalSpec ] ; // Error, object possibly undefined
171
- iSpec [ null ! as keyof PublicSpec ] ; // Error, object possibly undefined
197
+ iSpec [ null ! as keyof InternalSpec ] ;
198
+ iSpec [ null ! as keyof PublicSpec ] ; // Error
172
199
if ( iSpec === undefined ) {
173
200
return;
174
201
}
@@ -327,29 +354,52 @@ function once(emittingObject, eventName) {
327
354
emittingObject . off ( eventName , 0 ) ;
328
355
emittingObject . off ( eventName , 0 ) ;
329
356
}
330
- // In an element access obj[x ], we consider obj to be in a constraint position, except when obj is of
331
- // a generic type without a nullable constraint and x is a generic type. This is because when both obj
332
- // and x are of generic types T and K, we want the resulting type to be T[K].
357
+ // In an element access obj[key ], we consider obj to be in a constraint position, except when
358
+ // obj and key both have generic types. When obj and key are of generic types T and K, we want
359
+ // the resulting type to be T[K].
333
360
function fx1(obj, key) {
334
361
var x1 = obj [ key ] ;
335
362
var x2 = obj && obj [ key ] ;
363
+ var x3 = obj === null || obj === void 0 ? void 0 : obj [ key ] ;
336
364
}
337
365
function fx2(obj, key) {
338
366
var x1 = obj [ key ] ;
339
367
var x2 = obj && obj [ key ] ;
368
+ var x3 = obj === null || obj === void 0 ? void 0 : obj [ key ] ;
340
369
}
341
370
function fx3(obj, key) {
371
+ var x1 = obj [ key ] ;
372
+ var x2 = obj && obj [ key ] ;
373
+ var x3 = obj === null || obj === void 0 ? void 0 : obj [ key ] ;
374
+ }
375
+ function fx4(obj, key) {
376
+ var x1 = obj [ key ] ;
377
+ var x2 = obj && obj [ key ] ;
378
+ var x3 = obj === null || obj === void 0 ? void 0 : obj [ key ] ;
379
+ }
380
+ function fx5(obj, key) {
381
+ var x1 = obj [ key ] ;
382
+ var x2 = obj && obj [ key ] ;
383
+ var x3 = obj === null || obj === void 0 ? void 0 : obj [ key ] ;
384
+ }
385
+ function fx6(obj, key) {
342
386
var x1 = obj [ key ] ; // Error
343
387
var x2 = obj && obj [ key ] ;
388
+ var x3 = obj === null || obj === void 0 ? void 0 : obj [ key ] ;
389
+ }
390
+ function fx7(obj, key) {
391
+ var x1 = obj . x [ key ] ; // Error
392
+ var x2 = obj && obj . x [ key ] ;
393
+ var x3 = obj === null || obj === void 0 ? void 0 : obj . x [ key ] ;
344
394
}
345
395
// Repro from #44166
346
396
var TableBaseEnum = /** @class */ (function () {
347
397
function TableBaseEnum ( ) {
348
398
}
349
399
TableBaseEnum . prototype . m = function ( ) {
350
400
var iSpec = null ;
351
- iSpec [ null ] ; // Error, object possibly undefined
352
- iSpec [ null ] ; // Error, object possibly undefined
401
+ iSpec [ null ] ;
402
+ iSpec [ null ] ; // Error
353
403
if ( iSpec === undefined ) {
354
404
return ;
355
405
}
0 commit comments