相关疑难解决方法(0)

类型{}不存在Typescript属性

我在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 的文档(示例部分)中的代码段相同。

javascript typescript

3
推荐指数
2
解决办法
1万
查看次数

Angular2 中的“{}”类型不存在属性

我已经使用 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'。

typescript angular

2
推荐指数
1
解决办法
7032
查看次数

标签 统计

typescript ×2

angular ×1

javascript ×1