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
declareconsta:{b?:string};if(!a||a.b==="foo"){}
ESLint Config
module.exports={parser:"@typescript-eslint/parser",rules:{"@typescript-eslint/prefer-optional-chain":["error",{}],},};
tsconfig
{"compilerOptions": {}}Expected Result
I expect that no error from@typescript-eslint/prefer-optional-chain is triggered on the third line, as an optional chain would change behavior.
Actual Result
An error from@typescript-eslint/prefer-optional-chain is triggered on the third line. When autofixed, this produces the code
declareconsta:{b?:string};if(a?.b==="foo"){}
Whena.b is undefined, the original comparison produced the valuetrue, executing the code within theif-block. The 'autofixed' code producesfalse in that case, skipping the code within theif-block.
Additional Info
This seems due to the changes in#11533. The comment in#11533 (comment) already hints at this incorrect behavior.