我遇到了一个问题,即导入一个类仅用作类型记录类型注释会导致no-unused vars
错误。这个帖子说要将"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
放在代码中每个“未使用”导入的前面。这不是一个最佳的解决方案,所以我不讨论这个问题。
发布于 2021-08-17 20:18:11
更新(一年后):我已经犯了几次错误,我发现jsut重新启动TypeScript服务通常会修复它。
在IntelliJ Idea窗口的右下角,单击"Vue TypeScript ",然后单击“重新启动TypeScript服务”。一两秒钟后,所有的“错误”都将被重新评估,任何错误标记为错误都应该被清除。
这也可以用于“修复”TypeScript错误检查器中的许多其他问题。
发布于 2021-03-14 18:21:39
我也有过同样的经历。我怀疑这只是电脑的“坏心情”.所以我把这句话写进了评论中,只是我自己在下面写了同样的东西。编译器保持沉默,所以我删除了前一行。
可能只是个窃听器。
发布于 2021-09-28 03:11:20
跳过@typescript-eslint/解析器vue文件
添加.eslintignore
文件
# @typescript-eslint/parser can not parse vue v-on
src/view/example/index.vue
https://stackoverflow.com/questions/63615103
复制相似问题