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
RebeccaStevens opened this issue Sep 9, 2020 · 1 comment
Closed

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

RebeccaStevens opened this issue Sep 9, 2020 · 1 comment

Comments

@RebeccaStevens
Copy link

@RebeccaStevens RebeccaStevens commented Sep 9, 2020

  • 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
@bradzacher
Copy link
Member

@bradzacher bradzacher commented Sep 9, 2020

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
…n type arguments

Fixes #2527
@bradzacher bradzacher self-assigned this Sep 13, 2020
@bradzacher bradzacher added the has pr label Sep 13, 2020
bradzacher added a commit that referenced this issue Sep 13, 2020
…n type arguments (#2554)

Fixes #2527
phaux added a commit to phaux/typescript-eslint that referenced this issue Sep 28, 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.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants