Template Literals 7 exercises

Splitting A String into a Tuple

Let's dive deeper into template literals by looking at splitting a string at the type level.

We start with a type named Path that just is expressed as a string literal:

type Path = "Users/John/Documents/notes.txt"


Your challenge is to update SplitPath to be a tuple

Loading exercise


0:00 Let's dive deeper into template literals. We're now going to try and split a string at the type level.

0:07 We have a Path here inside a type, which is just being expressed as a string literal. We want SplitPath to equal that path but split into all of its constituent bits inside a tuple.

0:21 You see that this is basically an array here, except it's an array of certain named elements, and that's what we want it to look like.

0:29 There is a tool that can help you with this, which is S ts-toolbelt. There's a link to some documentation here, which we'll explore in the solution, to show you a little really useful tool to help you get this done.