This course has been updated! We now recommend you take the React and TypeScript, v2 course.

Check out a free preview of the full React and TypeScript course:
The "Utility Types Solution" Lesson is part of the full, React and TypeScript course featured in this preview video. Here's what you'd learn in this lesson:

Steve live codes the solution to the Utility Types exercise.

Get Unlimited Access Now

Transcript from the "Utility Types Solution" Lesson

>> So, mission again was to take over the end user model, and just exclude, well exclude maybe not the right word, but the conceptually exclude just account ID. And so previously, we've called Are the types that we're using as props, whatever the current use, or whatever the component is props, so we could make one called current user props.

[00:00:28] And the one we're gonna use this case is omit. And that's gonna take the user model as the first generic and there's gonna figure out. We're gonna remove any property called account ID. So if we hover over this one we can see this get used whenever defined. Which is fine.

[00:00:54] If you don't spell account ID, right it doesn't work. Just fun fact. And so now you can see it takes off account ID. And we've just got display name and verify. So if we go and we swap it in, we'll use a model was here, you can see that my account ID is no longer allowed.

[00:01:13] It's not a thing that I could use. This. So this allows us not to have to duplicate our code and have a second one where we take something off, so on and so forth, but actually kinda be programmatic about our types. Our other mission is, this is effectively the same, but I wanna be able to see if I can read the type of the current user component In order to use it for a friend.

[00:01:37] And with that we saw that we had the react.component props. And so for here we can do. And we're gonna type of what type of is a JavaScript keyword, but it works in our typescript definitions as well. So we use type of and then current user. And you can see that this is getting the same to proper display name, and is off of the current user as well.

[00:02:13] Cool, and so everything works here and it's all wired up together.