Type Transformations Workshop (9 exercises)

Introducing Type Helpers

Let's look at a new pattern called the Type Helper pattern.

We'll start with a ReturnWhatIPassIn type helper where anything we pass in will be returned.

For example, if we create a type Something and call ReturnWhatIPassIn, we should get back 'Something':

More examples of the desired behavior can be seen in our tests:


In our code's current state, the result of calling ReturnWhatIPassIn ends up being typed as any.

Your challenge is to update ReturnWhatIPassIn to behave as expected.

Hint: Currently we get the any type returned because the things we pass in aren't generic. This keyword should give you a clue about the syntax you want to find in the TypeScript Docs.


[0:00] It's now time to look at a new pattern here, called the type helper pattern. What we're going to do is we want to make this a ReturnWhatIPassIn type helper, where anything that we pass in will be returned.
[0:16] What that means is if we have, let's say, type Something = ReturnWhatIPassIn, I should be able to pass Something in there and have Something end up as Something. Currently, it's just any, because this is not particularly valid, because type ReturnWhatIPassIn is not generic. That should give you a clue about what type of syntax we're looking for here. Good luck.