Skip to content

Instantly share code, notes, and snippets.

@ustun
Created August 16, 2016 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ustun/2830789219ae94bbeab438279c267eaa to your computer and use it in GitHub Desktop.
Save ustun/2830789219ae94bbeab438279c267eaa to your computer and use it in GitHub Desktop.
Function type declaration for flowtype
//@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