【发布时间】:2019-01-25 11:18:15
【问题描述】:
有人能解释一下为什么你不能在 Typescript 中这样做吗?
this.obj.id = 1;
this.obj.str = 'This is string';
但你可以这样做:
this.obj = { id: 1, str: 'This is string'};
【问题讨论】:
-
this.obj最初是什么?如果您没有定义它,那么您正在尝试在不存在的东西上定义属性。 -
因为你不能设置
undefined的属性。
标签: typescript