Skip to content

Instantly share code, notes, and snippets.

@inomdzhon
Last active August 17, 2022 16:38
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 inomdzhon/732860e4d7b94470efeb801d2b33998c to your computer and use it in GitHub Desktop.
Save inomdzhon/732860e4d7b94470efeb801d2b33998c to your computer and use it in GitHub Desktop.

HOC typing

Typescript

function higherOrderFn<T extends (...args: any[]) => any>(fn: T): (...args: Parameters<T>) => ReturnType<T> {
  return (...args: Parameters<T>) => {
    return fn(args);
  };
}

Flow

function higherOrderFn<T, R>(fn: (arg: T) => R): T => R {
  return function (arg: T): R { return fn(arg); };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment