【问题标题】:Connecting typescript errors to their associated compiler options (tsconfig.json)将 typescript 错误连接到其关联的编译器选项 (tsconfig.json)
【发布时间】:2020-05-07 22:54:19
【问题描述】:

如何找出与给定 Typescript 错误相关的编译器选项?

我在VSCode中使用Typescript,Typescript经常指出问题,比如initializer provides no value for this binding element

(请注意这是由 Typescript 生成的警告,而不是 TSLint)。

tsconfig.json,我可以关闭特定的警告,比如

"compilerOptions": {
  "noImplicitAny": false,
  "strictPropertyInitialization": false
}

但据我所知,没有办法找出哪个编译器选项与哪个错误相关联。

目前有线索,但没有解决方案:

此 SO 帖子 Complete list of Typescript error codes and their fixes 提供了消息列表,但未提供使用哪个编译器选项启用/禁用消息。

不幸的是,编译器选项的名称并不模仿错误的措辞,因此您无法通过tsconfig.json 中的简单智能感知找到错误。

此外,官方文档似乎也没有提供这样的错误到选项映射:https://www.typescriptlang.org/docs/handbook/tsconfig-json.htmlhttps://www.typescriptlang.org/docs/handbook/compiler-options.html

所以,只是重申一下这个问题:我怎样才能找出关闭哪个编译器选项来消除给定错误?

【问题讨论】:

    标签: typescript visual-studio-code tsc


    【解决方案1】:

    错误消息和编译器设置之间没有 1:1(或 1:n 或 n:1)的对应关系,并且绝大多数错误无法使用任何编译器选项关闭。许多编译器选项会以某种方式改变行为,这意味着您无法可靠地说出与其他一些选项相反的情况会发生什么。

    对于确实有相应标志的错误消息,错误文本通常会提示它

    • "x" implicitly has type 'any'noImplicitAny
    • Unreachable code detectedallowUnreachableCode
    • Unused label detectedallowUnusedLabels
    • "x" is possibly "null"strictNullChecks
    • Local "x" is unusednoUnusedLocals

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-15
      • 2021-03-31
      • 2017-01-16
      • 2021-07-01
      • 2017-02-13
      • 1970-01-01
      • 2018-10-20
      • 1970-01-01
      相关资源
      最近更新 更多