DEV Community

Discussion on: Advanced TypeScript Exercises - Question 1

Collapse
 
dwjohnston profile image
David Johnston

Ah, so this is where the infer keyword is useful:

type Transform<A> = A extends Promise<infer T> ? T : never; 
Enter fullscreen mode Exit fullscreen mode

Basically, the infer keyword here lets us start referencing a new type, that didn't come from the original type declaration. In this case - we are returning it.