.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / type-fest / source / promise-value.d.ts
1 /**
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.
5
6 @example
7 ```
8 import {PromiseValue} from 'type-fest';
9
10 type AsyncData = Promise<string>;
11 let asyncData: PromiseValue<AsyncData> = Promise.resolve('ABC');
12
13 type Data = PromiseValue<AsyncData>;
14 let data: Data = await asyncData;
15
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();
19
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'));
23 ```
24 */
25 export type PromiseValue<PromiseType, Otherwise = PromiseType> = PromiseType extends Promise<infer Value>
26         ? { 0: PromiseValue<Value>; 1: Value }[PromiseType extends Promise<unknown> ? 0 : 1]
27         : Otherwise;