Awaited

Medium
built-in
recursion
infer
conditional types

Description:

If we have a type which is a wrapped type like Promise, how we can get the type which is inside the wrapped type?

For example: if we have Promise<PromiseType> how to get PromiseType?

type PromiseType = Promise<string> type Result = MyAwaited<PromiseType> // string

Please pay your attention that this type should unwrap nested promises:

type NestedPromiseType = Promise<Promise<Promise<string>>>; type Result = MyAwaited<NestedPromiseType> // string

Code

Loading...