Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jeroenvisser101 opened this issue Oct 18, 2019 · 4 comments · Fixed by #1169
Closed

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

jeroenvisser101 opened this issue Oct 18, 2019 · 4 comments · Fixed by #1169
Labels
bug Something isn't working has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin scope analyser Issues that are caused by bugs/incomplete cases in the scope analyser

Comments

@jeroenvisser101
Copy link

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
@jeroenvisser101 jeroenvisser101 added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Oct 18, 2019
@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for team members to take a look labels Oct 19, 2019
@bradzacher bradzacher changed the title [no-use-before-define] Optional chaining confuses rule (TS 3.7) [no-use-before-define] False positive with optional chaining Oct 21, 2019
@bradzacher bradzacher added the scope analyser Issues that are caused by bugs/incomplete cases in the scope analyser label Oct 21, 2019
@ghost
Copy link

ghost commented Oct 29, 2019

FWIW eslint(no-undef) also complains the same thing.

@bradzacher
Copy link
Member

This is known - #1116

@peoplenarthax
Copy link

This is known - #1116

Hej, in #1116 the do not ref to the same error, they refer to no-undef while here is "@typescript-eslint/no-use-before-define" what fails as well

@bradzacher
Copy link
Member

That was in response to the the comment directly above, which said that no-undef has the error as well...

If you have an issue, please file a new one.

@typescript-eslint typescript-eslint locked as resolved and limited conversation to collaborators Nov 19, 2019
@bradzacher bradzacher added this to the scope analysis rewrite milestone Apr 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin scope analyser Issues that are caused by bugs/incomplete cases in the scope analyser
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants