Conditional Types and Infer 10 exercises

Extract Type Arguments to Another Type Helper

In this exercise we have an interface MyComplexInterface which is acting as a type helper.

The interface takes arguments for Event, Context, Name, and Point, each being put into getEvent, getContext, getName, and getPoint, respectively.

interface MyComplexInterface<Event,

Loading exercise


0:00 In this exercise, we have an interface here, which is acting as a type helper. On this interface, we have Event, Context, Name, and Point. These are all the arguments. They get put into getEvent, getContext, getName, getPoint.

0:14 Now, we want to create another type helper called GetPoint, where when we pass in a MyComplexInterface, we return the Point that's there. We could do some interesting stuff here. Really, I want you to focus on trying to extract the generic from the generic slots in there, from the generic argument.

0:36 This Point, what we can do is, using infer, we can actually extract that out directly without having to go into MyComplexInterface itself and grab getPoint and grab the return type or something crazy like that.

0:49 That's your job here, is to try and find a way to use infer to extract out something from the type arguments of something that's being passed in. Good luck.