Type Transformations Workshop (9 exercises)

Extract Parts of a String with a Template Literal

In this exercise, we're going to combine the template literal and infer techniques we’ve learned so far.


We have a tuple of Names:

Your challenge is to complete the GetSurname<T> type so that it extracts the last name (if present) from each of the full names.


[0:00] [0: 00] Here we're going to combine two things that we've learned. We have already learned about template literals. Now we're going to use infer to extract out the bit that we want.
[0:10] [0: 10] Here we have a bunch of different names inside a tuple. GetSurname(), we're going to call it on those names and extract out the second name here. I've added a bunch of famous guitarists, including myself. We want to just extract out that last name, if they have one.