2 Returns the type that is wrapped inside a `Promise` type.
3 If the type is a nested Promise, it is unwrapped recursively until a non-Promise type is obtained.
4 If the type is not a `Promise`, the type itself is returned.
8 import {PromiseValue} from 'type-fest';
10 type AsyncData = Promise<string>;
11 let asyncData: PromiseValue<AsyncData> = Promise.resolve('ABC');
13 type Data = PromiseValue<AsyncData>;
14 let data: Data = await asyncData;
16 // Here's an example that shows how this type reacts to non-Promise types.
17 type SyncData = PromiseValue<string>;
18 let syncData: SyncData = getSyncData();
20 // Here's an example that shows how this type reacts to recursive Promise types.
21 type RecursiveAsyncData = Promise<Promise<string> >;
22 let recursiveAsyncData: PromiseValue<RecursiveAsyncData> = Promise.resolve(Promise.resolve('ABC'));
25 export type PromiseValue<PromiseType, Otherwise = PromiseType> = PromiseType extends Promise<infer Value>
26 ? { 0: PromiseValue<Value>; 1: Value }[PromiseType extends Promise<unknown> ? 0 : 1]