Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 相当于elvis“返回”;操作人员_Typescript_Null - Fatal编程技术网

Typescript 相当于elvis“返回”;操作人员

Typescript 相当于elvis“返回”;操作人员,typescript,null,Typescript,Null,如果nextbitmap()的结果为空,则Kotlin中的以下代码将从父函数返回 这类运算符的Typescript等价物是什么?没有这类运算符,return永远不能是表达式的一部分。在TypeScript中,您必须使用单独的if语句: const bitmap = nextbitmap(); if (!bitmap) return; // something the relies on bitmap not being null (或在条件中使用bitmap!=null,如果bitmap具有基

如果nextbitmap()的结果为空,则Kotlin中的以下代码将从父函数返回


这类运算符的Typescript等价物是什么?

没有这类运算符,
return
永远不能是表达式的一部分。在TypeScript中,您必须使用单独的
if
语句:

const bitmap = nextbitmap();
if (!bitmap) return;
// something the relies on bitmap not being null
(或在条件中使用
bitmap!=null
,如果
bitmap
具有基元类型)

返回(或抛出)形式是特定的,不同于合并形式,否则不会影响流控制。与Kotlin不同,TypeScript中的
return
关键字显然不是表达式。希望标题编辑时能引出反映意图的答案,如图所示。您所说的“脱离父函数”是什么意思?JavaScript只能从当前函数返回。我所说的“parent”是指调用上述代码段的函数。或者你所说的“当前”
const bitmap = nextbitmap();
if (!bitmap) return;
// something the relies on bitmap not being null