如何将返回值键入为“ throw”

时间:2018-09-29 22:08:42

标签: flowtype

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

1 个答案:

答案 0 :(得分:1)

流具有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]