参见英文答案 > Typescript the safe navigation operator ( ?. ) or (!.) and null property paths 4个
> Replacement of Elvis Operator of Angular2 in Typescript 2个
我们在.NET中有Null合并运算符,我们可以使用如下
string postal_code = address?.postal_code;
我们可以在React JS中做同样的事情吗?
我发现我们可以用&& ;;操作者
在address.ts文件中
string postal_code = address && address.postal_code;
我需要什么样的.net功能可以在typescript中使用react JS,这可能吗?
就像是:
string postal_code = address?.postal_code // I am getting the error in this line if I try to use like .NET
最佳答案
这是TypeScript中提出的功能,在传奇的Issue #16下
在此功能的ECMAScript规范确定之前,它不会被引入到TypeScript中,因为TypeScript实现需要遵循该规范 – 因此您可以尽早获得它,但在这种情况下不会很早.
它被称为以下任何一种:
>空传播运算符
>存在运算符
> Null Coalesce Operator