8. 实现 Awaited
简单
假如我们有一个 Promise
对象,这个 Promise
对象会返回一个类型。在 TypeScript 中,我们用 Promise<T>
中的 T
来描述这个 Promise
返回的类型。请你实现一个工具类型,可以获取这个类型。
例如:Promise<ExampleType>
,请你返回 ExampleType
类型。
type ExampleType = Promise<string>
type Result = MyAwaited<ExampleType> // string
需要注意,无论嵌套多少层 Promise
,要返回的类型是最里面的一层类型。
例如:Promise<Promise<ExampleType>>
,返回的是 ExampleType
类型,而不是 Promise<ExampleType>
。