Does TypeScript have a Null-conditional operator

前端 未结 6 1289
误落风尘
误落风尘 2020-12-11 00:10

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\"
         


        
6条回答
  •  萌比男神i
    2020-12-11 00:13

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

    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

提交回复
热议问题