Advanced TypeScript Exercises - Question 1

macsikora

Pragmatic Maciej

Posted on February 6, 2020

Advanced TypeScript Exercises - Question 1

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 **/
Enter fullscreen mode Exit fullscreen mode

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.

đź’– đź’Ş đź™… đźš©
macsikora
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