我找到了这样的代码:
const dealType = currentDealType ?? originalDealType ?? '';
?? ??
的语法是什么意思?
最佳答案
它是为 ecmascript 提出并已在 Typescript 中实现的无效合并运算符。您可以阅读更多 here 或 here
它的要点是
const dealType = currentDealType ?? originalDealType;
相当于:
const dealType = currentDealType !== null && currentDealType !== void 0 ? currentDealType : originalDealType;
或者说:如果
currentDealType
是 null
或 undefined
使用 originalDealType
otehrwise 使用 currentDealType
关于typescript - TypeScript 中的双双问号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62426269/