Skip to content

Instantly share code, notes, and snippets.

@fahrradflucht
Created December 14, 2018 19:39
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 fahrradflucht/b38ee5bd1b281281e9ab960d6b875713 to your computer and use it in GitHub Desktop.
Save fahrradflucht/b38ee5bd1b281281e9ab960d6b875713 to your computer and use it in GitHub Desktop.
type ArgumentsType<T> = T extends (...args: infer A) => unknown ? A : never;
const add = (a: number, b: number): number => a + b
type Add = typeof add;
function logAdd(...args: ArgumentsType<Add>): ReturnType<Add> {
const [a, b] = args;
const result = add(a, b)
console.log(a, b, result)
return result
}
@fahrradflucht
Copy link
Author

fahrradflucht commented Dec 14, 2018

ReturnType<T> is a predefined conditional type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment