Last change
on this file since bdd6491 was 6a3a178, checked in by Ema <ema_spirova@…>, 4 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
715 bytes
|
Line | |
---|
1 | import {PromiseValue} from './promise-value';
|
---|
2 |
|
---|
3 | type AsyncFunction = (...args: any[]) => Promise<unknown>;
|
---|
4 |
|
---|
5 | /**
|
---|
6 | Unwrap the return type of a function that returns a `Promise`.
|
---|
7 |
|
---|
8 | There has been [discussion](https://github.com/microsoft/TypeScript/pull/35998) about implementing this type in TypeScript.
|
---|
9 |
|
---|
10 | @example
|
---|
11 | ```ts
|
---|
12 | import {AsyncReturnType} from 'type-fest';
|
---|
13 | import {asyncFunction} from 'api';
|
---|
14 |
|
---|
15 | // This type resolves to the unwrapped return type of `asyncFunction`.
|
---|
16 | type Value = AsyncReturnType<typeof asyncFunction>;
|
---|
17 |
|
---|
18 | async function doSomething(value: Value) {}
|
---|
19 |
|
---|
20 | asyncFunction().then(value => doSomething(value));
|
---|
21 | ```
|
---|
22 | */
|
---|
23 | export type AsyncReturnType<Target extends AsyncFunction> = PromiseValue<ReturnType<Target>>;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.