简体   繁体   中英

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 :

{
  "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.

How do I have to configure object-literal-sort-keys to make this error go away?

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. To be able to this, tslint needs to know of the tsconfig.json file used in the same application. This can be provided as a flag, either --project or --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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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