[英]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_modules
的typescript
。 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.