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

Imported modules only used as type annotation are marked as no-unused-vars #5

Closed
doits opened this issue Nov 15, 2019 · 3 comments
Closed

Comments

@doits
Copy link

doits commented Nov 15, 2019

Thanks for the latest update to v5! If just tried it out and it works fine, though I know have another problem which I don't exactly know if estlint-config-typescript introduced it or something else ...

My config looks like this:

    "extends": [
      "eslint:recommended",
      "plugin:vue/recommended",
      "plugin:jest/recommended",
      "@vue/eslint-config-typescript",
      "@vue/eslint-config-prettier"
    ],

Now in my .vue files if I do this, I get a no-unused-vars error:

...
import { Location } from "vue-router/types"

export default Vue.extend({
  ...
  methods: {
    getLocation(): Location {
      return { name: "some_location" }
    }
  }
})

// => no-unused-vars: 'Location' is defined but never used

The key points are:

  • Location is only imported because it is used as a type annotation
  • Location is never explicitly used but as the return type of the method
  • Other imports work fine which are used inside methods or computed getters beside type annotation

I didn't have this before upgrading to v5, but a lot of things changed during that upgrade (new peer dependencies, other packages upgraded) so I'm sorry if this is the wrong place to report it.

Is this something that can be fixed here or elsewhere?

@doits doits changed the title Imported modules as type are marked as no-unused-vars Imported modules only used as type annotation are marked as no-unused-vars Nov 15, 2019
@doits
Copy link
Author

doits commented Nov 15, 2019

Allright, sorry, fixed it with this:

    "extends": [
      "eslint:recommended",
      "plugin:@typescript-eslint/eslint-recommended",
      "plugin:@typescript-eslint/recommended",
      "plugin:vue/recommended",
      "plugin:jest/recommended",
      "@vue/eslint-config-typescript",
      "@vue/eslint-config-prettier"
    ],

Looks like I was missing the plugin:@typescript-eslint/recommended part, see https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin

@doits doits closed this as completed Nov 15, 2019
@haoqunjiang
Copy link
Member

You can use the recommended set from this package, too, so that you won't need to manually add plugin:@typescript-eslint/eslint-recommended and plugin:@typescripteslint/recommended.

See https://github.com/vuejs/eslint-config-typescript#vueeslint-config-typescriptrecommended

@Naartti
Copy link

Naartti commented Feb 24, 2020

Had the same issue when starting a new project with vue cli (4.2.0) (with standard eslint-rules) and had to change .eslintrc to:

extends: [
    'standard',
    'plugin:vue/essential',
    '@vue/typescript',
    '@vue/standard',
    '@vue/typescript/recommended',
    '@vue/eslint-config-typescript',
  ]

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

No branches or pull requests

3 participants