Template Literals 7 exercises
Problem

Create an Object Whose Keys Are Derived From a Union

Now we'll start with a type called TemplateLiteralKey:


type TemplateLiteralKey = `${"user" | "post" | "comment"}${"Id" | "Name"}`;

When we hover over it, we can see that it's creating a union out of two unions that are mashed together in a template literal:


// On hover
type

Loading exercise

Transcript

0:00 In this problem, we have a TemplateLiteralKey here. If we hover over this, we can see that it's basically creating userId, userName, postId, postName, commentID, commentName out of these two unions that it's mashing together.

0:14 Our job now is to create an object of those keys where you basically have all of these automatically generated for you.

0:23 That's your job, is to take this TemplateLiteralKey that's being represented here. You don't have to change anything here. All you have to do is assign something to this unknown and turn it into an object.