@flowtype How to define a type of return of a fn based on an argument string? Asked twice on SO - Thanks stackoverflow.com/questions/… #flowtype

Aug 25, 2017 Β· 1:53 PM UTC

The intersection approach is a good one. You could also use $ElementType with a utility map type: flow.org/try/#0CYUwxgNghgTiA…
4
1
Also is there any utility that extracts the return of a function? const a = ():number => 6; $returnOf<a> would then be number.
1
1
There are ways to do this with generic types and *. I want to add a $Call type which works like $ObjMap which would also let you do this.
1
To simulate $Call this should work: type $Call<T, Fn> = $PropertyType<ObjMap<{p: T}, Fn>, 'p'>
2
Then: type $returnOf<A> = $Call<A, <R>(() => R) => R>
1
This should work 😊