UNPKG

637 BTypeScriptView Raw
1/**
2Returns the type that is wrapped inside a `Promise` type.
3If the type is not a `Promise`, the type itself is returned.
4
5@example
6```
7import {PromiseValue} from 'type-fest';
8
9type AsyncData = Promise<string>;
10let asyncData: PromiseValue<AsyncData> = Promise.resolve('ABC');
11
12type Data = PromiseValue<AsyncData>;
13let data: Data = await asyncData;
14
15// Here's an example that shows how this type reacts to non-Promise types.
16type SyncData = PromiseValue<string>;
17let syncData: SyncData = getSyncData();
18```
19*/
20export type PromiseValue<PromiseType, Otherwise = PromiseType> = PromiseType extends Promise<infer Value> ? Value : Otherwise;