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 have searched for related issues and found none that matched my issue.
- I have read the FAQ and my problem is not listed.
Playground Link
Repro Code
type Store = {
entries?: Record<string, { func(): void }>;
};
const obj: 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
Expected Result
I expected not to see a noUncheckedIndexedError
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)