Reputation: 340
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)
}
Upvotes: 6
Views: 3758
Reputation: 2385
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 🙂
Upvotes: 7