TypeScript 有空条件运算符吗 [英] Does TypeScript have a Null-conditional operator

查看:44
本文介绍了TypeScript 有空条件运算符吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有像 ?.在可以检查变量是否为空或未像 Kotlin 一样定义的 TypeScript 中?喜欢

Is there any operator like ?. in TypeScript that can check if the variable is null or not defined like Kotlin? Like

person?.getName()?.firstName ?: "None"

推荐答案

不,到目前为止,安全导航操作仍然没有在 Typescript 中实现:https://github.com/Microsoft/TypeScript/issues/16

No, as of now safe navigation operatior is still not implemented in Typescript: https://github.com/Microsoft/TypeScript/issues/16

然而,根据最新的标准化会议记录,它已经被提出,所以可能是 v3 :)

However according to the latest standardization meeting notes it has been proposed, so maybe v3 :)

https://github.com/tc39/agendas/blob/master/2017/07.md

这篇关于TypeScript 有空条件运算符吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆