tslint:"object-literal-shorthand" 的好处

tslint: benefit of "object-literal-shorthand"

此规则的示例:

    this.http.post(this.apiUrl + "screenshot", {
        url: url,
        ratio: ratio
    }).subscribe(res => {
        console.log(res);
    });

tslint 会抱怨这段代码。 tslint 希望我这样做的方式是

    this.http.post(this.apiUrl + "screenshot", {
        url,
        ratio
    }).subscribe(res => {
        console.log(res);
    });

对我来说,第一个片段的排列更加合理。我禁用了相应的规则,但现在我想知道在性能或其他方面使用 "object-literal-shorthand" 是否有任何好处。

我认为这会变得非常混乱,尤其是当字面量更大并且混合了不能使用 shorthand 的变量时。那么这条规则的原因是什么,我不明白。

这是 tslint 中的 fixable 规则之一。

https://palantir.github.io/tslint/usage/cli/

当你运行:

tslint --fix

它将重写代码以使用文字语法。

benefit of using the "object-literal-shorthand" in terms of performance

该规则是更短代码片段 规则集合的一部分,有助于生成更少的代码行。

So whats the reason for this rule, I don't get it.

tslint 中的可修复规则旨在协助代码共享。您可以添加 Git 挂钩或构建阶段,它们会 运行 tslint --fix 自动为您服务。

使用显示 tslint 警告的现代 IDEs 的人并没有真正从可修复功能中受益。 IDE 会在你写的时候打扰你修复它。

如果你不想打开它就关掉它。