Skip to content
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

[no-use-before-define] False positive on type guard cast #2527

Closed
3 tasks done
RebeccaStevens opened this issue Sep 9, 2020 · 1 comment · Fixed by #2554
Closed
3 tasks done

[no-use-before-define] False positive on type guard cast #2527

RebeccaStevens opened this issue Sep 9, 2020 · 1 comment · Fixed by #2554
Assignees
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

Comments

@RebeccaStevens
Copy link
Contributor

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

{
  "rules": {
    "@typescript-eslint/no-use-before-define": "error"
  }
}
import { isNumber } from 'type-guards';
type Id = number;

const isId = isNumber as (value: unknown) => value is Id;

Expected Result

No error, value is part of the type, it's not being "used".

Actual Result

const isId = isNumber as (value: unknown) => value is Id;
//                                           ~~~~~ 'value' was used before it was defined. (eslint@typescript-eslint/no-use-before-define)

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 4.1.0
@typescript-eslint/parser 4.1.0
TypeScript 4.0.2
ESLint 7.2.0
node 12.18.1
@RebeccaStevens RebeccaStevens added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Sep 9, 2020
@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for maintainers to take a look labels Sep 9, 2020
@bradzacher
Copy link
Member

This is a fun bug because technically (value: unknown) creates a "value" variable in the function type's scope (x is y and typeof x both require that x is a "value" variable, not a "type" variable).

So the rule is seeing a "value" variable with no initialisation and reporting. Should be a pretty easy fix.

bradzacher added a commit that referenced this issue Sep 13, 2020
@bradzacher bradzacher self-assigned this Sep 13, 2020
@bradzacher bradzacher added the has pr there is a PR raised to close this label Sep 13, 2020
bradzacher added a commit that referenced this issue Sep 13, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 14, 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
Projects
None yet
2 participants