source: trip-planner-front/node_modules/type-fest/source/promise-value.d.ts@ eed0bf8

Last change on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.0 KB
Line 
1/**
2Returns the type that is wrapped inside a `Promise` type.
3If the type is a nested Promise, it is unwrapped recursively until a non-Promise type is obtained.
4If the type is not a `Promise`, the type itself is returned.
5
6@example
7```
8import {PromiseValue} from 'type-fest';
9
10type AsyncData = Promise<string>;
11let asyncData: PromiseValue<AsyncData> = Promise.resolve('ABC');
12
13type Data = PromiseValue<AsyncData>;
14let data: Data = await asyncData;
15
16// Here's an example that shows how this type reacts to non-Promise types.
17type SyncData = PromiseValue<string>;
18let syncData: SyncData = getSyncData();
19
20// Here's an example that shows how this type reacts to recursive Promise types.
21type RecursiveAsyncData = Promise<Promise<string> >;
22let recursiveAsyncData: PromiseValue<RecursiveAsyncData> = Promise.resolve(Promise.resolve('ABC'));
23```
24*/
25export type PromiseValue<PromiseType, Otherwise = PromiseType> = PromiseType extends Promise<infer Value>
26 ? { 0: PromiseValue<Value>; 1: Value }[PromiseType extends Promise<unknown> ? 0 : 1]
27 : Otherwise;
Note: See TracBrowser for help on using the repository browser.