我开始在我的 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/