我有一个问题,我需要在对象 Json 中添加新的属性,但我在 TypeScript 中发现了这个问题
error TS2339: Property 'condition' does not exist on type '{ field: string; value: string; operator: string; }'
这是我的代码:
var request = [{
field: "company_id",
value: this.authService.getCurrentCompany().af_row_id,
operator: '='
}];
if (categoryId != null) {
request[0].condition = "AND";
}
最佳答案
您可以为 request
定义一个类型,或者您可以只向对象字面量添加一个 condition
字段并让 TypeScript 隐式确定类型。例如
var request = [{
field: "company_id",
value: this.authService.getCurrentCompany().af_row_id,
operator: '=',
condition: undefined
}];
if (categoryId != null) {
request[0].condition = "AND";
}
关于javascript - 在 TypeScript 中添加新属性 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41049481/