Skip to content

Instantly share code, notes, and snippets.

@turbod
Created February 11, 2024 12:00
Show Gist options
  • Save turbod/45e207695e069881390b6e376776971f to your computer and use it in GitHub Desktop.
Save turbod/45e207695e069881390b6e376776971f to your computer and use it in GitHub Desktop.
function add(a: number, b: number): number {
return a + b;
}
type Test = typeof add;
// ^ = type Test = (a: number, b: number) => number
type Test2 = ReturnType<typeof add>;
// ^ = type Test2 = number
//
type MyReturnType<T> = T extends (...args: any[]) => infer R ? R : any;
type Test3 = MyReturnType<typeof add>;
// ^ = type Test3 = number
//
//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment