我们在类中创建一个对象:
class AppComponent {
dish = {};
loadDishWindow(){
console.log(this.dish);
//->Object {}
this.dish = {
attributes : [],
id : null ,
name : "",
type : null,
type_id: null,
unit: null,
unit_id: null
};
console.log(this.dish);
//->Object {attributes: Array[0], id: null, name: "", type: null, type_id: null…}
}
为什么,如果我在这个方法中调用console.log(this.dish.name);,而不是在最后console.log()一个方法中调用,例如,它会在编译期间出错吗?
error TS2339: Property 'name' does not exist on type '{}'.
我用一口
为什么:
(你好静态类型)
解决方案:
更新:
关于null和undefined在这里 写下他们的恕我直言在这里
表达很有趣