使 compilerOptions 在 tsconfig 中生成警告而不是错误

Bra*_*UAR 11 typescript tslint visual-studio-code

有没有办法在 tsconfig.json 文件中将选项 noUnusedLocals 和 noUnusedParameters 指示为警告而不是阻止编译的错误?

目前我在 tsconfig.json 文件中使用它们,如下所示:

  "compilerOptions": {
    "noUnusedLocals": true,
    "noUnusedParameters": true
  },
Run Code Online (Sandbox Code Playgroud)

我试过这个选项:

“没有未使用的变量”:真,

在 tslint.json 文件中,但它没有检测到像 tsc 这样的错误,并且在 Visual Studio 代码中我看不到它们带有下划线。

Mat*_*hen 8

您可能已经看到,Visual Studio Code 有一个技巧,可以在实时编辑期间将 noUnusedLocals 和 noUnusedParameters 问题显示为警告(该typescript.reportStyleChecksAsWarnings设置默认为 true)。tslint 扩展根本不显示这些问题,因为它们需要类型信息,而tslint 扩展不支持.

如果问题是您正在使用类似的东西tsc --noEmitOnError并且您不希望 noUnusedLocals/noUnusedParameters 错误阻止发出,那么您可以让 Visual Studio Code 使用tsconfig.json启用了 noUnusedLocals/noUnusedParameters 的一个,并让您的命令行构建使用tsc单独的tsconfig.json禁用了选项,加上tslint没有未使用的变量。