Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Closed
Description
Before You File a Bug Report Please Confirm You Have Done The Following...
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I havesearched for related issues and found none that matched my issue.
- I haveread the FAQ and my problem is not listed.
Playground Link
Repro Code
typeStore={entries?:Record<string,{func():void}>;};constobj:Store={entries:{entry1:{func(){}},},};// using optional chaining falsely produces no-unnecessary-condition:obj.entries?.entry1?.func();// even though the type of the `entry1` property includes undefined// but omitting the optional chaining produces a type error:obj.entries?.entry1.func();// 18048: 'obj.entries.entry1' is possibly 'undefined'.
ESLint Config
{"rules":{"@typescript-eslint/no-unnecessary-condition":"error"}}
tsconfig
{"compilerOptions": {"strict":true,"noUncheckedIndexedAccess":true }}
Expected Result
I expectednot to see anoUncheckedIndexedError
when performing property access on a nested, possibly-undefined value
Actual Result
no-unnecessary-condition raises an error on the optional chain in the last property access, even though using standard (non-optional) property access raises a type error (see playground)
Additional Info
This example worked correctly in 8.18.0 (before#10460)