Reputation: 71
I'm using Vue with Vue CLI and Typescript.
I imported interface from vuex file and used it for mapState
type annotation.
But eslint shows me an error.
'State' is defined but never used. eslint(no-unused-vars)
Code
import { Component, Vue } from 'vue-property-decorator';
import { mapState } from 'vuex';
import { State } from '@/store/index';
@Component({
computed: mapState<State>({
cards: (state: State) => state.user.cards,
})
})
export default class Home extends Vue {}
.eslintrc.js
module.exports = {
root: true,
env: {
node: true
},
'extends': [
'plugin:vue/essential',
'eslint:recommended',
'@vue/typescript'
],
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'quotes': ['error', 'single'],
'semi': ['warn', 'always']
},
parserOptions: {
parser: '@typescript-eslint/parser'
}
};
What should I do not to see the eslint error?
Upvotes: 7
Views: 2332
Reputation: 12748
EsLint default no-unused-vars
has an bug, that reproduces like you explain. According to my source [1] it should be fixed by using @typescript-eslint/no-unused-vars
like so:
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'
}
}
]
Source [2] is another question on same topic. There, my solution [1] is one option among others. In [2] and [3] it is said you need the @typescript-eslint/eslint-plugin
and @typescript-eslint/parser
installed like so:
npm install --save-dev eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin
[1] https://github.com/vuejs/eslint-config-typescript/issues/14
[2] ESLint - Configuring "no-unused-vars" for TypeScript
[3] https://khalilstemmler.com/blogs/typescript/eslint-for-typescript/
Upvotes: 1