Type Transformations Workshop (4 exercises)
Problem

Create a Union Type From an Object’s Keys

Consider this object with several testing frameworks as keys:

Challenge

The vitest, jest, and mocha keys need to be extracted into a union type.

Now, you could satisfy the test by manually creating a union like so:

But the ideal solution is to create the union by directly extracting keys from the object using typeof and some new syntax I haven’t shown you yet.

Hint: Look through the TypeScript Handbook to find an operator that seems helpful.

Transcript

[0:00] In this exercise, we have a bunch of testing frameworks here. We want to extract a union type of each of these keys. We want to get Vitest, Jest, and Mocker into a union. What that's going to look like is we could do this with Vitest or Jest, or Mocker here.
[0:20] That's going to satisfy our test. Ideally, we want to extract this from the object here. That's your job. We're going to need typeof again. We're also going to need a new bit of syntax that we've never seen before. Good luck.