UNPKG

691 BTypeScriptView Raw
1type AsyncFunction = (...arguments_: any[]) => Promise<unknown>;
2
3/**
4Unwrap the return type of a function that returns a `Promise`.
5
6There has been [discussion](https://github.com/microsoft/TypeScript/pull/35998) about implementing this type in TypeScript.
7
8@example
9```ts
10import type {AsyncReturnType} from 'type-fest';
11import {asyncFunction} from 'api';
12
13// This type resolves to the unwrapped return type of `asyncFunction`.
14type Value = AsyncReturnType<typeof asyncFunction>;
15
16async function doSomething(value: Value) {}
17
18asyncFunction().then(value => doSomething(value));
19```
20
21@category Async
22*/
23export type AsyncReturnType<Target extends AsyncFunction> = Awaited<ReturnType<Target>>;