简体   繁体   English

如何在 Visual Studio Code 中因缺少导入而突出显示错误?

[英]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.

相关问题 如何在 Visual Studio 中获得 Jslib 文件的语法高亮显示 - How do i get syntax highlighting for a Jslib file in Visual Studio Visual Studio Code - 缺少 JavaScript 的大多数语法突出显示 - Visual Studio Code - Missing most syntax highlighting for JavaScript 获取Visual Studio代码以为自定义Javascript导入提供智能感知 - Get Visual Studio Code to give intellisense for custom Javascript imports 如何使 Visual Studio Code 使用路径映射进行自动导入? - How to make Visual Studio Code use path mappings for automatic imports? 在 Visual Studio 代码中运行“node -v”时出现错误 - I get an error running "node -v" in visual studio code Intellisense无法在Visual Studio Code中使用导入 - Intellisense not working with imports in Visual Studio Code KnockoutJs和模板 - Visual Studio中没有代码突出显示/完成? - KnockoutJs and Templates - No code highlighting / completion in visual studio? 如何使用WebMatrix和Visual Studio调试代码? - How can I debug my code using WebMatrix and Visual Studio? 如何在 Visual Studio 中编码此 api 请求的结果 - How can I code the result of this api request in visual studio 如何在 Visual Studio 代码上修复智能感知? - How can i fix intelliSense on visual studio code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM