我在Typescript中有以下代码。为什么编译器会引发错误?
var object = {};
Object.defineProperty(object, 'first', {
value: 37,
writable: false,
enumerable: true,
configurable: true
});
console.log('first property: ' + object.first);
Run Code Online (Sandbox Code Playgroud)
js.ts(14,42):错误TS2339:类型“ {}”上不存在属性“ first”。
与mozilla 的文档(示例部分)中的代码段相同。
我已经使用 http 调用获取数据。但是,我在编译时显示了上述错误。
用户组件.ts
this._user.saveUsers(model).then(data => {
if(data.success==true){
this.router.navigate(['/user/list']);
}else{
console.log("data")
}
});
Run Code Online (Sandbox Code Playgroud)
注意:我的对象是动态的。取决于我的 http 调用
错误:
app/users/users.component.ts(33,21):错误 TS2339:类型“{}”上不存在属性“成功”。app/users/users.component.ts(34,38):错误 TS2339:类型“{}”上不存在属性“数据”。app/users/users.component.ts(76,25): 错误 TS2339: 类型 '{}' 上不存在属性 'success'。