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]: typedefs option doesn't work #249

Closed
Hotell opened this issue Feb 11, 2019 · 4 comments
Closed

[no-use-before-define]: typedefs option doesn't work #249

Hotell opened this issue Feb 11, 2019 · 4 comments
Assignees
Labels
bug Something isn't working 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

@Hotell
Copy link
Contributor

Hotell commented Feb 11, 2019

Repro

{
  "rules": {
    "typescript/no-use-before-define": ["error",{"typedefs": true}]
  }
}
// Should error according to docs, but it wont

let myVar: StringOrNumber = 'hello'
type StringOrNumber = string | number

Expected Result

Should work according to docs

Actual Result

Doesn't work at all

Additional Info

Also dunno if this is considered within the implementation, but there is a common pattern in React to get Props/State types from implementation by leveraging typeof. So if typedefs is set to false this should not raise any error:

type State = typeof initialState
const initialState = { count: 0, who: ''}

Versions

package version
@typescript-eslint/eslint-plugin 1.3.0
@typescript-eslint/parser X.Y.Z
TypeScript 3.3.3
ESLint 5.12
node 8.15
npm X.Y.Z
@Hotell Hotell added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Feb 11, 2019
@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for maintainers to take a look labels Feb 11, 2019
@bradzacher
Copy link
Member

@armano2 has been working on a solution to this (and other scope issues), see #233.

@armano2
Copy link
Member

armano2 commented Feb 14, 2019

@bradzacher my PR is giving us possibility to support types but it will not fix this issue, we have to add support for it to this rule.

types will be stored in separated property (they can't collide with variables)

@aMarCruz
Copy link

The same error with the same config and this:

type Props = { foo: typeof Foo };  // <= 'Foo' was using before it was defined

const Foo = () => {};

@bradzacher bradzacher added the scope analyser Issues that are caused by bugs/incomplete cases in the scope analyser label Apr 19, 2019
kaicataldo pushed a commit to kaicataldo/typescript-eslint that referenced this issue Aug 27, 2019
…t-eslint#252)

When user has `git core.autocrlf` set to crlf on windows machines there are collisions between `eslint-docs` and `prettier` due to inconsistent line endings in md files.

fixes: typescript-eslint#249
@bradzacher bradzacher added this to the scope analysis rewrite milestone Apr 6, 2020
@bradzacher
Copy link
Member

Merging into #1856

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working 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

No branches or pull requests

4 participants