高级 TypeScript 练习 - 问题 1
如果我们有一个像 这样的包装类型Promise
,那么我们如何获取包装类型内部的类型呢?例如,如果我们有 ,Promise<ExampleType>
该如何获取ExampleType
?
看看下面的代码。编写一个实用程序类型Transform
,它将接受一个泛型类型参数,如果是,Promise
它将计算其内部的类型。
type X = Promise<string>
type Y = Promise<{ field: number }>
type ResultX = Transform<X>; // ResultX type equals string
type ResultY = Transform<Y>; // ResultY type equals { field: number }
type Transform<A> = /** here your answer **/
在评论区发表你的答案吧!祝你玩得开心!答案很快就会公布!
如果您对下一篇文章的通知感兴趣,请在dev.to和twitter上关注我。
文章来源:https://dev.to/macsikora/advanced-typescript-exercises-question-1-45k4