【发布时间】:2019-08-23 12:24:41
【问题描述】:
现在我进行以下检查:
return this.profile.organization ? this.profile.organization.shifts : null;
我可以美化这个属性检查存在吗?
所以,我的意思是:
this.profile.organization.shifts || '';
【问题讨论】:
-
类似,答案适用,但问题的措辞不同..stackoverflow.com/questions/50211847/typescript-optional-types/…
-
遗憾的是,没有像 C# 和许多其他语言那样的空条件运算符。见stackoverflow.com/questions/45441086/… 和stackoverflow.com/questions/15260732/…
-
但我通常使用'&&'运算符。如果左边的表达式是truthy,它将计算右边的表达式
标签: typescript