[英]How can I get error highlighting for missing imports in Visual Studio Code?
When working with Visual Studio Code on Windows to develop Angular applications, I recall that if I removed an import statement, vscode would almost immediately underline in red all of the places where those artifacts were being referenced.当在 Windows 上使用 Visual Studio Code 开发 Angular 应用程序时,我记得如果我删除了一个导入语句,vscode 几乎会立即在所有引用这些工件的地方用红色下划线。
However, now I am working in vscode on a Mac to develop React applications, and I've noticed that if I remove an import statement, I do not get any red-underlining like I am used to.但是,现在我在 Mac 上使用 vscode 开发 React 应用程序,我注意到如果我删除导入语句,我不会像以前那样得到任何红色下划线。
Any thoughts as to how I can get this functionality back?关于如何恢复此功能的任何想法? I imagine its due to an Angular package I had installed on my previous workspace, that I no longer have.
我想这是由于我在以前的工作空间中安装的 Angular package 造成的,我不再拥有了。
By default, VS Code only checks the syntax of JS files and will not complain about undefined variables like it does with TypeScript默认情况下,VS Code 只检查 JS 文件的语法,不会像 TypeScript 那样抱怨未定义的变量
You can follow these instructions to enable type checking in plain old JS files.您可以按照这些说明在普通的旧 JS 文件中启用类型检查。 The simplest approach is to add
//@ts-check
at the top of the file最简单的方法是在文件顶部添加
//@ts-check
@Matt Bierner gave a good advice to check instructions , but after reading it I can say that the best option is to create or modify jsconfig.json
by adding "checkJs": true
@Matt Bierner 给出了检查说明的好建议,但在阅读后我可以说最好的选择是通过添加
"checkJs": true
来创建或修改jsconfig.json
: true
{
"compilerOptions": {
"checkJs": true,
},
"exclude": ["node_modules", "**/node_modules/*"]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.