-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Closed
Labels
accepting prsGo ahead, send a pull request that resolves this issueGo ahead, send a pull request that resolves this issuebugSomething isn't workingSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin
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
declare const a: { b?: string };
if (!a || a.b === "foo") {
}ESLint Config
module.exports = {
parser: "@typescript-eslint/parser",
rules: {
"@typescript-eslint/prefer-optional-chain": ["error", {}],
},
};tsconfig
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
declare const a: { b?: string };
if (a?.b === "foo") {
}When a.b is undefined, the original comparison produced the value true, executing the code within the if-block. The 'autofixed' code produces false in that case, skipping the code within the if-block.
Additional Info
This seems due to the changes in #11533. The comment in #11533 (comment) already hints at this incorrect behavior.
ruben-moxio, dennis-c, hdrent, B4nan, kirkwaiblinger and 10 more
Metadata
Metadata
Assignees
Labels
accepting prsGo ahead, send a pull request that resolves this issueGo ahead, send a pull request that resolves this issuebugSomething isn't workingSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin
{ "compilerOptions": {} }