VS 代码显示 eslint 错误,但 vitest 正在工作。 'vi' 未定义

问题描述 投票:0回答:2

我有一个像这样的 tsconfig 文件

{
  "include": ["tests/**/*.ts"],
  "exclude": [],
  "compilerOptions": {
    "composite": true,
    "lib": [],
    "skipLibCheck": true,
    "outDir": "lib",
    "types": ["vitest/globals"]
  }
}

因为我已经为 vitest/globals 定义了类型,所以

yarn vitest
cmd 工作正常并执行测试用例。但在 VS Code 中它显示错误

如何在 vs-code 中修复/静音它?

visual-studio-code vuejs2 vitest
2个回答
13
投票

我必须将以下内容添加到我的

.eslintrc.json
文件中才能在测试设置模块中修复此问题:

"globals": {
  "vi": true
},

但是,如果您使用 TypeScript,您还应该将其添加到您的

compilerOptions
中的
tsconfig.json
:

"types": ["vitest/globals"]

编辑:你的

tsconfig.json
中已经有了这个,但无论如何我都会把它留在这里,以防它对某人有帮助


0
投票

我对这个问题的解决方案是将

.eslintrc.js
文件中的 ecmaVersion 从
2020
增加到
2022
,如下所示:

// ...
parserOptions: {
  ecmaVersion: 2022,
},
// ...

由于您使用的是 TypeScript,您也可以尝试将目标设置为 2022 年,如下所示:

// ...
"compilerOptions": {
  "target": "ES2022",
  // ...
},
// ...
© www.soinside.com 2019 - 2024. All rights reserved.