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 Node = {
[name in `${Uppercase<string>}${string}`]?: Node;
} & {
[name in `${Lowercase<string>}${string}`]?: string;
};
export function test(root: Node) {
// Unnecessary optional chain on a non-nullish value
console.log(root.Foo?.Bar?.baz);
// 'root.Foo.Bar' is possibly 'undefined'
console.log(root.Foo?.Bar.baz);
}
ESLint Config
{
"rules": {
"@typescript-eslint/no-unnecessary-condition": "error"
}
}
tsconfig
Expected Result
I expect the optional chaining to be allowed on line 9.
Actual Result
A lint error is emitted on line 9
Additional Info
The playground contains some more code, showing cases where things work and where things don't.
This issue is likely related to #9754