Last active
April 4, 2021 01:05
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://tsplay.dev/mMyO6m