angular - 为什么 tslint 删除对象键?

标签 angular typescript lint tslint

我开始在我的 TypeScript 项目中使用 tslint。当我查看 linted 源代码时,我注意到有时键会从对象中删除。

我(本地)进行了生产构建,没有显示任何错误。这怎么可能?我在网上找不到有关此行为的信息。

之前:

this.streamsDataModelDistance = new SimpleStreamsDataModel({
            polylineValueModels: polylineValueModels,
            fields: this.settingsModel.fields,
            commuters: distanceCommuters
        });

之后:

this.streamsDataModelDistance = new SimpleStreamsDataModel({
            polylineValueModels,
            fields: this.settingsModel.fields,
            commuters: distanceCommuters
        });

请注意缺少键“polylineValueModels”。

这如何编译成 JavaScript 而不会出现错误?我犹豫是否要把它放进后备箱。

最佳答案

您刚刚启用了 object-literal-shorthand 规则,您可以在 tslint.json 文件中设置它。

{
 "rules": {
    "object-literal-shorthand": false
  }
}

https://palantir.github.io/tslint/rules/object-literal-shorthand/

这不是错误,这是 ECMAScript 2015 的标准语法。

In ECMAScript 2015, a shorthand notation is available, so that the keyword "function" is no longer necessary.

// Shorthand property names (ES2015)
var a = 'foo', b = 42, c = {};
var o = {a, b, c};

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer

关于angular - 为什么 tslint 删除对象键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58624168/

相关文章:

javascript - 共享服务: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked

angular - 如何在失去焦点时将输入文本值格式化为 Angular 4 上的货币?

twitter-bootstrap - Uncaught ReferenceError : Popper is not defined - with Bootstrap 4 and Webpack 3. 8.1

javascript - 从用户服务中的 firestore 返回用户数据返回 null

angular - 如何禁用primeng数据表中的复选框

angular - 在 Angular 8 组件中切换 MatSlideToggle

javascript - 在 Notepad++ 中使用 JSLint

javascript - 所有测试都给出相同的失败结果,但为什么呢?

android - 请在执行 SonarQube 之前构建项目并检查编译类的位置

android - 如何 lint Android 系统/平台应用程序