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

And*_*kin 5 typescript visual-studio-code

例如,这个例子

async function a() { await null; }
Run Code Online (Sandbox Code Playgroud)

VS Code 中的等待有一个小警告

'await' has no effect on the type of this expression. ts(80007)
Run Code Online (Sandbox Code Playgroud)

如何使该警告的行为类似于 VS Code 中的错误tsc(更明显,编译失败)?

Sou*_*man 0

为了tsc将此视为错误,需要有一个编译器标志,您可以设置与我在查看他们的文档async-await时无法找到的相关的编译器标志。

然而,有一个 linting 规则(假设您已经eslint设置)会导致您的 linter 在这种情况下抱怨。有关其工作原理的说明,请参阅eslint 文档。

综上所述,如果您确实特别想要这种行为。我认为您可以将此诊断消息的类别编辑为"Error"您的node_modulesfor typescript. 这种方法对我来说有点脆弱,所以我肯定会鼓励使用 linter 方法!

至于eslint与 VSCode 集成,有一个插件可以将 linting 警告直接集成到编辑器中。我怀疑您可以直接从 VSCode 本身的市场将其添加到您的 VScode 中。