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)
}
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)
}
Share
Improve this question
asked Oct 27, 2017 at 17:47
FerryFerry
3402 silver badges12 bronze badges
4
- 1 Create a delegate and you can use it the same way. – Erick Stone Commented Oct 27, 2017 at 17:49
- @ErickStone sorry, but I don't have a clue for it. May provide an example? – Ferry Commented Oct 27, 2017 at 18:37
- blog.slaks/2011/07/… This covers the basics. – Erick Stone Commented Oct 27, 2017 at 19:17
-
2
e.g.
const f = (x :number) : (number => number) => y => x + y
– user6445533 Commented Oct 27, 2017 at 19:51
1 Answer
Reset to default 7You 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/try