在我的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": []
}然而,我总是会遇到这样的错误:
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.我已经尝试了文档中显示的例子,但是它们不能解决这个问题。删除此错误的唯一方法是使用object-literal-sort-keys默认设置,但随后我必须按字母顺序对所有数组进行排序。
如何配置object-literal-sort-keys以消除此错误?
发布于 2022-08-11 21:57:28
"match-declaration-order"规则的选项对象-文字-排序键要求tslint具有类型信息,因为它需要检查对象文本和它们定义的类型。为了能够做到这一点,tslint需要知道在同一个应用程序中使用的tsconfig.json文件。这可以作为标志提供,无论是--project还是--p。完整的命令如下所示:
npx tslint -p tsconfig.json -c tslint.json这将链接到为该项目编译的每个文件。
https://stackoverflow.com/questions/73247282
复制相似问题