This is how you annotate a variable / constant as holding a function of a particular type:
declare type TFunction = () => any;
const foo: TFunction = function foo() {};
What is the syntax when one declares a function:
function boo() {}
?
This is how you annotate a variable / constant as holding a function of a particular type:
declare type TFunction = () => any;
const foo: TFunction = function foo() {};
What is the syntax when one declares a function:
function boo() {}
?
On
Coming late to this question, but if you are talking about declarations in the sense of "compile-time declarations, separate from code, that use the declare keyword", then per the Flow declarations docs, you should be able to declare globals like this:
declare var boo: TFunction;
or scoped items as members of their containing module or type:
declare class FunctionHolder {
boo: TFunction;
}
There's no way to put
: TFunctionon yourfunction boo()declaration. However, you can flow check it by writing the no-op statement(boo: TFunction);afterward. The only drawback is this evaluatesbooat runtime.Probably the best way to do it though is to not worry about explicitly declaring that
boois aTFunction, and instead just rely on Flow to check it any time you useboowhere aTFunctionis expected.Here's a more concrete example of what I mean: (Try flow link)