打字稿中的可选链运算符 [英] Optional Chaining Operator in Typescript

查看:88
本文介绍了打字稿中的可选链运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 javascript 中,babel 插件.

In javascript, Optional Chaining Operator is supported by the babel plugin.

但是我在 Typescript 中找不到如何做到这一点.有什么想法吗?

But I can't find how to do this in Typescript. Any idea?

推荐答案

在撰写本文时,TypeScript 不支持可选链运算符.请参阅有关 TypeScript 问题跟踪器的讨论:https://github.com/Microsoft/TypeScript/issues/16

At time of writing, TypeScript does not support the optional chaining operator. See discussion on the TypeScript issue tracker: https://github.com/Microsoft/TypeScript/issues/16

作为警告,这个运算符的语义仍然非常在不断变化,这就是 TypeScript 尚未添加它的原因.今天针对 Babel 插件编写的代码将来可能会在没有警告的情况下改变行为,从而导致严重的错误.我通常建议人们不要开始使用行为尚未明确定义的语法.

As a warning, the semantics of this operator are still very much in flux, which is why TypeScript hasn't added it yet. Code written today against the Babel plugin may change behavior in the future without warning, leading to difficult bugs. I generally recommend people to not start using syntax whose behavior hasn't been well-defined yet.

这篇关于打字稿中的可选链运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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