Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to type return value as "throw"

Tags:

flowtype

Sometimes my function will throw. I want to add this to the return type. In TypeScript we set the return type to never. Is there an equivalent strategy in Flow?

like image 343
Noitidart Avatar asked Dec 28 '25 22:12

Noitidart


1 Answers

Flow have empty type. Take a look at example of Typing Redux reducers, also can work as returned type for function.

/* @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]
like image 93
Buggy Avatar answered Dec 30 '25 22:12

Buggy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!