Created
August 16, 2016 18:15
-
-
Save ustun/2830789219ae94bbeab438279c267eaa to your computer and use it in GitHub Desktop.
Function type declaration for flowtype
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//@flow | |
// define the function type | |
type FunctionThatTakesAStringAndReturnsANumber = (x: string) => number; | |
function higherOrderFunction(myFn: FunctionThatTakesAStringAndReturnsANumber) { | |
return "something"; | |
} | |
// or define the type inline | |
function higherOrderFunction2(myFn: (x: string) => number) { | |
return "something"; | |
} | |
higherOrderFunction(function (x: string) { | |
return 3; | |
}); | |
higherOrderFunction(function (x) { | |
return "ustun" | |
}) | |
higherOrderFunction2(function (x) { | |
return "ozgur" | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment