typescript - TypeScript 中的双双问号

标签 typescript

我找到了这样的代码:

const dealType = currentDealType ?? originalDealType ?? '';
?? ?? 的语法是什么意思?

最佳答案

它是为 ecmascript 提出并已在 Typescript 中实现的无效合并运算符。您可以阅读更多 herehere

它的要点是

const dealType = currentDealType ?? originalDealType;

相当于:
const dealType = currentDealType !== null && currentDealType !== void 0 ? currentDealType : originalDealType;

或者说:如果 currentDealTypenullundefined 使用 originalDealType otehrwise 使用 currentDealType

关于typescript - TypeScript 中的双双问号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62426269/

相关文章:

javascript - TypeScript Angular - 将字符串添加到数字属性会导致值为零 (0)

jquery - Angular 2在模板渲染后执行脚本

javascript - 使用此关键字的 typescript

typescript - 如何在 TypeScript 中定义具有任意数量的某种类型属性的接口(interface)

Angular 6 : Mat-tree-node selection/click event implementation

angular - ngIf 设置颜色?

angular - 无法使用 angular-cli 创建 Angular 5 项目

angular - 如何解决在 Angular 6 中为业力测试抛出的 [object ErrorEvent]

reactjs - 带有 React 类型的 TypeScript 将无法编译

google-maps - 如何在 Angular 2 中制作带有可点击国家/地区的 map ?