gpt4 book ai didi

flowtype - 如何将返回值键入 "throw"

转载 作者:行者123 更新时间:2023-12-02 02:50:09 25 4
gpt4 key购买 nike

有时我的函数会抛出异常。我想将其添加到返回类型。在 TypeScript 中,我们将返回类型设置为 never。 Flow 中是否有等效策略?

最佳答案

流有 empty 类型。看一下 Typing Redux reducers 的例子, 也可以作为函数的返回类型。

/* @flow */

function foo():empty {
throw new Error();
}

function baz():empty {
return 42;
}

return 42;
^ Cannot return `42` because number [1] is incompatible with empty [2].
References:
8: return 42;
^ [1]
7: function baz():empty {
^ [2]

关于flowtype - 如何将返回值键入 "throw",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52572944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com