d24f6ddecc9bcacc8d75633f7e959cb75a30c61cd78039d31facfea602c71ea9d2276a11ae283a281dce1f01f2eceab0049b7c8d6b72a535d68959f0f6f124 715 B

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