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

False positive no-unused-vars when importing typescript type in .vue file #14

Closed
WIStudent opened this issue Sep 2, 2020 · 5 comments
Closed

Comments

@WIStudent
Copy link

WIStudent commented Sep 2, 2020

I am getting a false positive error no-unused-vars when importing and using a typescript type in a .vue file.
My eslintrc.js:

module.exports = {
  root: true,
    env: {
      node: true
    },
    extends: [
      "plugin:vue/vue3-essential",
      "eslint:recommended",
      "@vue/typescript"
    ],
    parserOptions: {
      "parser": "@typescript-eslint/parser"
    },
    rules: {
      "@typescript-eslint/semi": ["error"]
    }
};

One possible workaround I found is to disable the no-used-vars rule for .vue files and enable @typescript-eslint/no-unused-vars:

overrides: [
  // Fix no-used-vars when importing ts types in .vue files
  {
    files: ["*.vue"],
    rules: {
      'no-unused-vars': 'off',
      '@typescript-eslint/no-unused-vars': 'error'
    }
  }
]
@WIStudent WIStudent changed the title False positive no-unused-var when importing typescript type in .vue file False positive no-unused-vars when importing typescript type in .vue file Sep 2, 2020
@ux-engineer
Copy link

Same here and not just for imported types...

@Livijn
Copy link

Livijn commented Nov 9, 2020

I am also receiving the same error. Here is a reproducible example.

<script lang="ts">
import { defineComponent, PropType } from 'vue';

export default defineComponent({
  name: 'HelloWorld',
  props: {
    msg: String as PropType<String>
  }
})
</script>

Throws error:
ESLint: 'PropType' is defined but never used.(no-unused-vars)

@backbone87
Copy link

backbone87 commented Dec 23, 2020

I have a similar problem with eslint core rule no-undef and global types.

The reason is that some eslint core rules should be disabled.

@vue/eslint-config-typescript only extends plugin:@typescript-eslint/eslint-recommended, but not plugin:@typescript-eslint/recommended, so no-unused-vars is not disabled. So extending plugin:@typescript-eslint/recommended should fix this issue.

In my case no-undef gets triggered inside vue files anyway. The reason for this is that plugin:@typescript-eslint/eslint-recommended only disables core rules for .ts/x files, but not .vue files. Except for copying over the rule disables, i have no solution here, yet.

edit:
The following override can be added to the .eslintrc.js to enable plugin:@typescript-eslint/eslint-recommended for vue files (should be early in the overrides):

  overrides: [
    {
      files: ['*.vue'],
      rules: require('@typescript-eslint/eslint-plugin').configs['eslint-recommended'].overrides[0].rules,
    },
  ],

@pr3tori4n
Copy link

pr3tori4n commented Jan 6, 2021

I'm seeing similar issues in our codebase. Can verify there's issues with no-unused-vars. Can also verify that WIStundent's workaround in the first comment fixes those.

Also was seeing issues with globals. I was able to resolve those by adding them to the globals in the config

globals: {
  foo: 'readonly',
}

@agentschmitt
Copy link

agentschmitt commented Jun 7, 2021

i have also problem with the rule no-undef when using the ruleset @vue/typescript/recommended

error: 'NotificationPermission' is not defined (no-undef) at src\views\Navigation.vue:72:28
public notification(): NotificationPermission {

segevfiner referenced this issue in vuejs/create-vue Sep 5, 2022
Airbnb & Standard options are not added yet.

The difference with the previous implementation is that we now
use `@vue/eslint-config-typescript` instead of
`@vue/eslint-config-typescript/recommended`, because I'm not very
satisfied with the current implementation of the latter config.
There are some edge cases that may confuse users.

I need to find time to refactor that package in the coming months.
robertstewart89 added a commit to robertstewart89/Eslint-config-develeop-laravel that referenced this issue Sep 24, 2022
Fixes vuejs/eslint-config-typescript#14
Fixes vuejs/create-vue#158

Technically turning new rules on would be a breaking change because
it introduces more errors in an existing codebase.
However, in our README we've already made it clear that this ruleset
should only be used with `@vue/cli` or `create-vue`, so an existing
`eslint:recommended` config is expected, thus no breaking changes.

Nevertheless, I choose to make it `warn` instead of `error` to minimize
the impact.
goldentroll added a commit to goldentroll/eslint-config-typescript that referenced this issue Mar 14, 2023
Fixes vuejs/eslint-config-typescript#14
Fixes vuejs/create-vue#158

Technically turning new rules on would be a breaking change because
it introduces more errors in an existing codebase.
However, in our README we've already made it clear that this ruleset
should only be used with `@vue/cli` or `create-vue`, so an existing
`eslint:recommended` config is expected, thus no breaking changes.

Nevertheless, I choose to make it `warn` instead of `error` to minimize
the impact.
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

6 participants