问题描述
我遇到一个问题,即导入仅用作打字稿类型注释的类会导致no-unused vars
错误。 This thread表示将"plugin:@typescript-eslint/recommended"
添加到eslint配置中,这解决了此问题,但引起了更多解析错误:
-
ESLint: Parsing error: Identifier expected
,发生在v-on:change
-
ESLint: Parsing error: '}' expected.
,发生在components: {}
中的@Component(...)
/App.vue
:
<template>
<div id="app" style="height: 100%">
<input v-on:change="onChange"/> <!--This is the "Identifier expected" error -->
</div>
</template>
<script lang="ts">
import { Component,Vue } from 'vue-property-decorator';
import Foo from "@/path/to/Foo";
import Bar from "@/path/to/Bar";
@Component({
components: { //This is where the `'}' expected.` error occurs
}
})
export default class App extends Vue {
onChange(e : any) : void {
let f : Foo = Bar.baz(); //This is what caused the "no-unused-vars" problem before
f.someFunc();
}
}
</script>
这是来自package.json的Eslint配置:
"eslintConfig": {
"root": true,"env": {
"node": true
},"extends": [
"plugin:vue/essential","eslint:recommended","@vue/typescript","plugin:@typescript-eslint/recommended"
],"parserOptions": {
"parser": "@typescript-eslint/parser"
},"rules": {}
}
我尝试过在vue/valid-v-on
中启用rules
,以及在上述GitHub线程中使用的其他exports
。
该如何解决?
谢谢。
编辑:我已经从eslint配置中删除了plugin:@typescript-eslint/recommended"
,并将行// eslint-disable-next-line no-unused-vars
放在了代码中每个“未使用”的导入上方。这不是一个最佳的解决方案,所以我将保留这个问题。
解决方法
我刚刚遇到了同样的事情。我怀疑这只是电脑的“坏心情”……所以我把这条线放在评论中,只是自己在下面写了同样的东西。编译器保持沉默,所以我删除了前一行。
可能只是一个错误。