Skip to content
This repository has been archived by the owner on Jan 19, 2019. It is now read-only.

Imported types cause false positives with no-unused-vars rule #457

Closed
Hilzu opened this issue Mar 29, 2018 · 6 comments
Closed

Imported types cause false positives with no-unused-vars rule #457

Hilzu opened this issue Mar 29, 2018 · 6 comments
Labels

Comments

@Hilzu
Copy link

Hilzu commented Mar 29, 2018

What version of TypeScript are you using?
2.7.2

What version of typescript-eslint-parser are you using?
14.0.0

What code were you trying to parse?

import { Server } from "http"
import app from "./app"

let server: Server | null = null

server = app.listen(() => {
  console.log("Listening on", server!.address())
})

What did you expect to happen?
No errors are reported with the no-unused-vars rule on

What happened?

src/test.ts
  1:10  error    'Server' is defined but never used  no-unused-vars

The no-unused-vars rule was previously mentioned in the readme as having known issues. Now that it's removed I expected the above code to work.

@kinyat
Copy link

kinyat commented Apr 17, 2018

We cannot turn on noUnusedLocals on local development as it is very annoying to have this blocking the complier.

Would really love to rely on eslint to check to allow compiling.

@tushar-singh
Copy link

I have this issue as well. Using the same workaround as kinyat via overrides (so I can still have these rules enabled in .js and .jsx files)

  "rules": { ... },
  "overrides": [
    {
      "files": ["**/*.ts", "**/*.tsx"],
      "rules": {
        "no-unused-vars": ["off"],
        "no-undef": ["off"]
      }
    }
  ]

@JamesHenry
Copy link
Member

There is already a custom rule in the plugin for no-unused-vars: https://github.com/nzakas/eslint-plugin-typescript/blob/master/docs/rules/no-unused-vars.md

If that rule is no sufficient for this use-case then a bug report should be filed against it, and ideally a PR submitted to extend at.

Thanks!

@KaelWD
Copy link

KaelWD commented Jun 15, 2018

I was using that, it fails if you import types that don't have a value.

'no-unused-vars': 'error',
'typescript/no-unused-vars': 'error',
// ERROR: 'Options' is defined but never used
import { VuetifyUseOptions as Options } from 'types'
...
// Even though I use it here as a type
export default function lang (config: Options['lang'] = {}): VuetifyLanguage {

@JamesHenry
Copy link
Member

As per my previous message, a bug report should be filed against the plugin, this is not a parsing issue

@KaelWD
Copy link

KaelWD commented Jun 15, 2018

Forgot this was a separate repo 😅

Looks like there is already a few:
nzakas/eslint-plugin-typescript#33
bradzacher/eslint-plugin-typescript#90
bradzacher/eslint-plugin-typescript#112

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants