Search code examples
typescripttypescript2.0

Does TypeScript have a Null-conditional operator


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"

Solution

  • 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