Deriving Types From Values 15 exercises
Problem

The keyof Operator

In this exercise, we're working with an interface named FormValues that contains name, email, and password properties:


interface FormValues {
name: string;
email: string;
password: string;
}

In addition to this, we have an inputs Record, which includes name, email,

Loading exercise

Transcript

00:00 In this exercise, we have an interface called form values that has name, email, and password on it. Then we have a set of inputs down here, which is a record of name, email, or password as a union. And the members of the record or the values of the record are initial value string and label string.

00:17 Then this object down here is basically name, email, and password all with these things like attached. Though there's a bit of duplication. Can you see it? In the interface, we have name, email, and password here. And in the record, we have name, email, and password too.

00:33 Wouldn't it be great if we could derive one from the other so that the form values was always the source of truth? Your job is to try to figure out a better way to type this line of code, the name, email, and password line of code, in order to derive it from the form values up there.

00:50 And there is a really useful little piece of TypeScript syntax called keyof, which is going to help you out. Good luck.