Closed
Description
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I have read the FAQ and my problem is not listed.
Repro
{
"rules": {
"@typescript-eslint/prefer-optional-chain": "error",
}
}
const foo = (bar || {}).baz;
// or
const foo = (bar|| {})[baz];
// or
const foo = (((a || {}).b || {}).c || {}).d;
Expected Result
The rule should suggest to use optional chaining
I'm working on a codebase that uses this pattern a lot (about ~60% of the cases I refactor to optional chaining arise from this pattern, the others come from &&
s) and I'm only getting prompted for the &&
cases.
I expect to get the same warnings/errors/suggestions the &&
case have, not including function calls
Actual Result
No error or warning
Additional Info
Willing to add a PR if needed
Tested this already against existing code in this repo
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin |
5.9.0 |
@typescript-eslint/parser |
5.9.0 |
TypeScript |
4.5.5 |
ESLint |
8.1.0 |
node |
14.17.5 |