Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Created November 12, 2021 20:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanflorence/90e36b58bd28a38cc775e988e26bcb94 to your computer and use it in GitHub Desktop.
Save ryanflorence/90e36b58bd28a38cc775e988e26bcb94 to your computer and use it in GitHub Desktop.
Infer the return type of a promise.
type Await<T extends (...args: any) => any> = T extends (
...args: any
) => Promise<infer U>
? U
: T extends (...args: any) => infer U
? U
: any;
async function load() {
return fetch("...");
}
type Thing = Await<typeof load>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment