【发布时间】:2020-05-26 10:43:07
【问题描述】:
将事物赋值为 null 或将 Union 类型运算符赋值为 null 有什么区别。无论哪种方式,这两种数据类型都允许类成员为空,所以想了解一下。行为有区别吗?
export class PropertyAddress {
city?: string = null;
state?: string = null;
zipcode?: string = null;
export class PropertyAddress {
city?: string | null;
state?: string | null;
zipcode?: string | null;
问题背景:
想要声明一个类,并确保所有成员都存在并以 null 开头,如果没有定义。有一个问题,即类成员没有出现在调试器中,如果他们没有被预设的话——
【问题讨论】:
标签: angular typescript angular8