Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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()

This comment has been minimized.

Copy link
Owner Author

@reconbot reconbot commented Apr 4, 2021

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