Wil*_*ert 5 typescript visual-studio-code
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.
Run Code Online (Sandbox Code Playgroud)
我已经安装@types/jest并添加jest到文件中的types字段,tsconfig但无法正常工作。
但是我注意到,它仅在子目录中发生,因为我具有具有以下文件结构的monorepo:
- app1
- app2
- app3
Run Code Online (Sandbox Code Playgroud)
如果仅打开app1文件夹,则不会出现任何错误。如何设置VSCode以与具有多个项目的文件夹一起使用?
我知道VSCode允许我们设置多个工作区,但这不是我想要的。每个文件夹都有自己node_modules的tsconfig文件。我只希望VSCode为每个文件夹识别它们,而不是查看的根级别node_modules。
我还尝试tsconfig在根级别创建一个文件,添加以下内容:
{
"compilerOptions": {
"typeRoots": ["app1/node_modules/@types", "app2/node_modules/@types"]
}
}
Run Code Online (Sandbox Code Playgroud)
但这没有用。
我遇到了类似的问题,我的问题是我在 tsconfig.json 中使用了“include”/“exclude”,如果文件未包含或被排除,则会导致类型混乱。删除了这两个选项,现在无需进一步配置即可工作。
如果这不是你的情况,我建议你看看:
https://github.com/Microsoft/vscode/issues/50910#issuecomment-393719145
| 归档时间: |
|
| 查看次数: |
103 次 |
| 最近记录: |