Skip to content

Instantly share code, notes, and snippets.

@hallettj

hallettj/time.ts Secret

Created January 22, 2019 19: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 hallettj/dd83d9afbebc74c10f782c4629319c13 to your computer and use it in GitHub Desktop.
Save hallettj/dd83d9afbebc74c10f782c4629319c13 to your computer and use it in GitHub Desktop.
type Arguments<T> = T extends (...args: infer A) => any ? A : never
type Return<T> = T extends (...args: any[]) => infer R ? R : never
function time<F extends Function>(fn: F, ...args: Arguments<F>): Return<F> {
console.time()
const result = fn(...args)
console.timeEnd()
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment