Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the type of function in flow javascript type checker?

How would you define type for functions in flow, in the context of function getting passed in as argument? For eg, afterDoneSomething below is callback function that's getting passed - I'm not sure how I define it's type with flow.

function doSomething(path:string, afterDoneSomething:<What is the Type>)
like image 271
opensourcegeek Avatar asked Nov 13 '15 11:11

opensourcegeek


1 Answers

According to the doc: http://flowtype.org/docs/functions.html, you need to supply the type of the function's parameters and returned value: (P1: T1, .., Pn: Tn) => U

So suppose your afterDoneSomething takes a number and return a number, it should be annotated as

function doSomething(path:string, afterDoneSomething: (x: number) => number)
like image 63
Lim H. Avatar answered Nov 15 '22 12:11

Lim H.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!