Skip to content

Instantly share code, notes, and snippets.

@reconbot
Last active April 4, 2021 01:05
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 reconbot/771288f35535b1718d93d4c0ea671d7a to your computer and use it in GitHub Desktop.
Save reconbot/771288f35535b1718d93d4c0ea671d7a to your computer and use it in GitHub Desktop.
This type will unwrap an async function and give you the type of the returned promise
type AsyncFuncReturn<T> = T extends (...args: any[]) => Promise<infer U> ? U : never
// eg
const randomFunction = async () => ({ a: 4, b: "string" })
type RandomReturn = AsyncFuncReturn<typeof randomFunction>
const foo: RandomReturn = await randomFunction()
@reconbot
Copy link
Author

reconbot commented Apr 4, 2021

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