Conditional Types and Infer 10 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:

type Names = [
"Matt Pocock",
"Jimi Hendrix",
"Eric Clapton",
"John Mayer",
"BB King"

Your challenge is to complete th

Loading exercise


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 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.