Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flow type for function that return function

From flow's function type docs, function that return primitive type is like this

const a = aFunc = (id: number): number => id + 1.

But, how to create flow type for a function that return a function?

const aFunc = (id: number): <what type?> => {
  return bFunc(a): void => console.log(a)
}
like image 792
Ferry Avatar asked Oct 27 '17 17:10

Ferry


1 Answers

You can either create a separate type, or you can do it inline.
Or you can choose to don't specify a return-type at all, because flow knows the return type of bFunc.

const bFunc = (a): void => console.log(a);

Separate type:

type aFuncReturnType = () => void;
const aFunc = (id: number): aFuncReturnType => () => bFunc(id);

Inline:

const aFunc = (id: number): (() => void) => () => bFunc(id);

You can also see this on flow.org/try 🙂

like image 78
MichaelDeBoey Avatar answered Sep 28 '22 07:09

MichaelDeBoey