简体   繁体   English

object-literal-sort-keys 需要类型信息才能使用“match-declaration-order”或“match-declaration-order-only”

[英]object-literal-sort-keys needs type info to use "match-declaration-order" or "match-declaration-order-only"

In my tslint.json I have object-literal-sort-keys defined as match-declaration-order :在我的tslint.json ,我将object-literal-sort-keys定义为match-declaration-order

{
  "defaultSeverity": "error",
  "extends": [
    "tslint:recommended"
  ],
  "jsRules": {},
  "rules": {
    "no-console": false,
    "object-literal-sort-keys": [
      true,
      "match-declaration-order"
    ],
    "max-line-length": [
      true,
      200
    ],
    "typedef": [
      true,
      "member-variable-declaration",
      "variable-declaration"
    ]
  },
  "rulesDirectory": []
}

However I'm always getting this error:但是我总是收到这个错误:

object-literal-sort-keys needs type info to use "match-declaration-order" or
"match-declaration-order-only".
See https://palantir.github.io/tslint/usage/type-checking/ for documentation on
how to enable this feature.

I have tried the examples shown in the documentation , but they don't solve the issue.我已经尝试了文档中显示的示例,但它们并没有解决问题。 The only thing removing this error is to use the object-literal-sort-keys default setting, but then I have to alphabetically sort all arrays.消除此错误的唯一方法是使用object-literal-sort-keys默认设置,但随后我必须按字母顺序对所有 arrays 进行排序。

How do I have to configure object-literal-sort-keys to make this error go away?我如何配置object-literal-sort-keys才能消除此错误 go?

The option "match-declaration-order" for the object-literal-sort-keys rule requires tslint to have type information, since it needs to check object literal against their defined type. object-literal-sort-keys规则的选项"match-declaration-order"要求 tslint 具有类型信息,因为它需要根据其定义的类型检查 object 文字。 To be able to this, tslint needs to know of the tsconfig.json file used in the same application.为此,tslint 需要知道同一应用程序中使用的tsconfig.json文件。 This can be provided as a flag, either --project or --p .这可以作为标志提供, --project--p The complete command will look like this:完整的命令将如下所示:

npx tslint -p tsconfig.json -c tslint.json

This will lint every file that would be compiled for the project.这将对将为项目编译的每个文件进行 lint。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM