Skip to content

[no-use-before-define] False positive with optional chaining #1104

Closed
@jeroenvisser101

Description

@jeroenvisser101

Repro

{
  "rules": {
    "@typescript-eslint/no-use-before-define": ["error"]
  }
}
const updatedAt = data?.updatedAt;
//                      ^^^^^^^^^
// 'updatedAt' was used before it was defined. (@typescript-eslint/no-use-before-define)

Expected Result
Would not produce any errors.

Actual Result
Produces an error:

// 'updatedAt' was used before it was defined. (@typescript-eslint/no-use-before-define)

Additional Info
This issue seems to only happen when the variable name is the same as the property name. For instance, the code below does not show the warning:

const timestamp = data?.updatedAt;

Versions

package version
@typescript-eslint/parser 2.4.0
TypeScript 3.7.0-beta (15 Oct 2019)
ESLint 6.5.1
node 12.11.1
npm 6.11.3
yarn 1.19.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghas prthere is a PR raised to close thispackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginscope analyserIssues that are caused by bugs/incomplete cases in the scope analyser

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions