在 visual studio 代码中格式化 TypeScript 时,转换生成 tslint 空白警告

When formatting TypeScript in visual studio code, a cast generates tslint whitespace warning

例如,当我有以下 TypeScript 代码时 const bar = <foo>{ answer: 42 } tslint 在 >{ 之间发出警告 'missing whitespace'。所以,要修复它,我必须写: const bar = <foo> { answer: 42 } 但是,每次我在 vs 代码 (SHIFT+ALT+F) 中格式化我的文件时,我的格式都会重置为顶部的版本,从而导致新的 tslint 问题。由于无法更改vs code中的格式规则,是否需要在tslint或editorconfig中添加规则?

您可以更改 tslint.json 并编辑项目中的 whitespace 规则。 您的示例看起来像 check-typecast 设置。

"check-typecast" checks for whitespace between a typecast and its target.

按照建议覆盖您的规则集:

"whitespace": [true, "check-branch", "check-decl", "check-operator", "check-separator", "check-type" ]
  "typedef-whitespace": [
  true,
  {
    "call-signature": "nospace",
    "index-signature": "nospace",
    "parameter": "nospace",
    "property-declaration": "nospace",
    "variable-declaration": "nospace"
  },
  {
    "call-signature": "onespace",
    "index-signature": "onespace",
    "parameter": "onespace",
    "property-declaration": "onespace",
    "variable-declaration": "onespace"
  }