如果 nextbitmap() 的结果为 null,则 Kotlin 中的以下代码从父函数返回
val bitmap = nextbitmap() ?: return
// something the relies on bitmap not being null
这种运算符的 Typescript 等价物是什么?
最佳答案
没有这样的操作符,而且return
永远不能成为表达式的一部分。在 TypeScript 中,您必须使用单独的 if
声明:
const bitmap = nextbitmap();
if (!bitmap) return;
// something the relies on bitmap not being null
(或在条件中使用 bitmap != null
,如果 bitmap
具有原始类型)
关于相当于 elvis “?: return” 运算符的 typescript ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64083222/