Advanced TypeScript Exercises - Question 1
Pragmatic Maciej
Posted on February 6, 2020
If we have a type which is wrapped type like Promise
. How we can get a type which is inside the wrapped type? For example if we have Promise<ExampleType>
how to get ExampleType
?
Take a look at below code. Write an utility type Transform
which will take a generic type argument, and if it is a Promise
it will evaluate to the type inside it.
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 **/
Post your answers in comments. Have fun! Answer will be published soon!
If you are interested in notifications about next articles please follow me on dev.to and twitter.
đź’– đź’Ş đź™… đźš©
Pragmatic Maciej
Posted on February 6, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
javascript How I Created Vanilla Calendar Pro — A Lightweight and Flexible JavaScript Calendar with TypeScript
November 28, 2024