Skip to content

prefer-optional-chain autofix is not safe #1820

Closed
@jasonHzq

Description

@jasonHzq

The autofix of rule "prefer-optional-chain" in eslint-plugin is not safe in this case:

source code:

// foo is null here
const value = foo && foo.value;

// value is null in source code
if (value === null) {
  // code here
}

autofixed code:

// foo is null here
const value = foo?.value;

// value will be undefined in autofix code
if (value === null) {
  // code here
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomershas prthere is a PR raised to close thispackage: 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