假如有一个 Promise
对象,这个 Promise
对象会返回一个类型。在 TS 中,我们用 Promise<T>
来描述这个 Promise
返回的类型。请你实现一个类型,可以获取这个类型
例如:Promise<ExampleType>
,请你返回 ExampleType
类型
type ExampleType = Promise<string>
type Result = MyAwaited<ExampleType> // string
答案
type MyAwaited<T> = T extends PromiseLike<infer R> ? R extends PromiseLike<any> ? MyAwaited<R> : R : never