VSCode 无法识别 Jest 类型。我收到以下错误:
Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig.
我已经安装了 @types/jest
并将 jest
添加到我的 tsconfig
文件中的 types
字段但是它不起作用。
但是我注意到,它只发生在子目录中,因为我有一个具有以下文件结构的 monorepo:
- app1
- app2
- app3
如果我只打开 app1
文件夹,那么我不会收到任何错误。如何设置 VSCode 以处理具有多个项目的文件夹?
我知道 VSCode 允许我们设置多个工作区,但这不是我想要的。每个文件夹都有自己的 node_modules
和一个 tsconfig
文件。我只想让 VSCode 为每个文件夹识别它们,而不是查看 node_modules
的根级别。
我还尝试在根级别创建一个 tsconfig
文件,添加以下内容:
{
"compilerOptions": {
"typeRoots": ["app1/node_modules/@types", "app2/node_modules/@types"]
}
}
但是没有用。
最佳答案
我遇到了类似的问题,我的问题是我在我的 tsconfig.json 中使用了“include”/“exclude”,如果文件未包含或被排除,它会混淆类型。删除了这两个选项,现在无需进一步配置即可使用。
如果这不是你的情况,我建议你看看:
https://github.com/Microsoft/vscode/issues/50910#issuecomment-393719145
关于typescript - VSCode 无法识别子目录中的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57452111/