If we have a type which is a wrapped type like Promise, how can we get the type which is inside the wrapped type?
For example: if we have Promise<ExampleType> how to get ExampleType?
type ExampleType = Promise<string>
type Result = MyAwaited<ExampleType> // string
This question is ported from the original article by @maciejsikora
import type { Equal, Expect } from '@type-challenges/utils'
type X = Promise<string>
type Y = Promise<{ field: number }>
type Z = Promise<Promise<string | number>>
type Z1 = Promise<Promise<Promise<string | boolean>>>
type T = { then: (onfulfilled: (arg: number) => any) => any }
type cases = [
Expect<Equal<MyAwaited<X>, string>>,
Expect<Equal<MyAwaited<Y>, { field: number }>>,
Expect<Equal<MyAwaited<Z>, string | number>>,
Expect<Equal<MyAwaited<Z1>, string | boolean>>,
Expect<Equal<MyAwaited<T>, number>>,
]