简体   繁体   English

在 Visual Studio Code 中使用 TypeScript 时,如何将 TS 警告配置为显示为错误?

[英]When using TypeScript in Visual Studio Code, how do I configure TS warnings to be shown as errors?

For example, this example例如,这个例子

async function a() { await null; }

has a small warning on await in VS Code在 VS Code 中有一个关于 await 的小警告

'await' has no effect on the type of this expression. ts(80007)

How do I make that warning behave like an error in VS Code and tsc (be more visible, fail compilation)?我如何使该警告表现得像 VS Code 和tsc的错误(更明显,编译失败)?

In order for tsc to treat this as an error, there would need to be a compiler flag that you could set pertaining to async-await which I wasn't able to find looking through their docs .为了让tsc将此视为错误,需要有一个编译器标志,您可以设置该标志与async-await ,我无法通过查看他们的文档找到。

There is, however, a linting rule (assuming you have eslint set up) which would cause your linter to complain in precisely this situation.然而,有一个 linting 规则(假设你已经设置了eslint )会导致你的eslint在这种情况下抱怨。 See the eslint docs for an explanation of how it works.请参阅eslint 文档以了解其工作原理。

All of that said, if you really want this behavior specifically.综上所述,如果您真的特别想要这种行为。 I think you could edit the category of this diagnostic message to be "Error" in your node_modules for typescript .我想你可以编辑的类别此诊断信息"Error"在你node_modulestypescript That approach feels a bit brittle to me so I would definitely encourage the linter approach!这种方法对我来说有点脆弱,所以我肯定会鼓励使用 linter 方法!

As far as integrating eslint with VSCode, there is a plugin which should integrate the linting warnings directly into the editor.至于将eslint与 VSCode 集成,有一个插件可以将 linting 警告直接集成到编辑器中。 I suspect you can add this to your VScode directly from their marketplace from within VSCode itself.我怀疑您可以直接从 VSCode 本身的市场中将其添加到您的 VScode 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为 Typescript 配置 Visual Studio Code? - How do I configure Visual Studio Code for Typescript? 在visual studio代码中,如何跳转到typescript类型定义index.d.ts中的实际代码? - In visual studio code, how do you jump to the actual code in a typescript type definitions index.d.ts? 如何在Visual Studio Code 1.9.1版中升级打字稿 - How do I upgrade typescript in Visual Studio Code version 1.9.1 使用 Typescript 使用 sequelize get 方法时,Visual Studio Code Intelisense 错误 - Visual Studio Code Intelisense falsely errors when using sequelize get method using Typescript 在 Visual Studio Code 中使用装饰器时出错 - Errors when using decorators in Visual Studio Code 在 Visual Studio 中将打字稿错误报告为警告,并且不会使构建失败 - Report typescript errors as warnings in Visual Studio and don't fail the build Node.d.ts使用打字稿编译器发布错误,如何解决? - Node.d.ts issues errors using typescript compiler, how do I fix? 如何将 .ts 文件的默认应用程序设置为 Visual Studio Code? - How do I set the default app for .ts files to Visual Studio Code? 在Visual Studio中使用TypeScript在lib.d.ts中出现100多个错误 - 100+ errors in lib.d.ts with TypeScript in Visual Studio 如何在Visual Studio Code项目中使用自定义.d.ts文件? - How do I make use of a custom .d.ts file in a Visual Studio Code project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM