Skip to content

[prefer-optional-chain] fixer produces wrong logic  #1438

Closed
@bradleyayers

Description

@bradleyayers

Repro

{
  "rules": {
    "@typescript-eslint/prefer-optional-chain": ["error"]
  }
}
declare const a: { b: string | null } | null;
a !== null && a.b !== null && a.b.length > 0;
/*
^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using an optional chain expression instead, as it's more concise and easier to read.
*/

Expected Result

a?.b != null && a.b.length > 0;

Actual Result

a?.b !== null && a.b.length > 0;
/*
                 ^ Object is possibly 'null'.
*/

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 2.15.0
@typescript-eslint/parser 2.15.0
TypeScript 3.7.3
ESLint 6.1.0
node 10.16.0
npm 6.9.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions