This course has been updated! We now recommend you take the TypeScript Fundamentals, v3 course.

Check out a free preview of the full TypeScript 3 Fundamentals, v2 course:
The "Built-In Utility Types" Lesson is part of the full, TypeScript 3 Fundamentals, v2 course featured in this preview video. Here's what you'd learn in this lesson:

Mike introduces the builtin utility types partial, pick, extract, exclude, and record

Get Unlimited Access Now

Transcript from the "Built-In Utility Types" Lesson

>> Mike North: TypeScript comes with a couple Utility Types and they have recently added a couple more that heavily depend on this conditional. Number one is Partial. Partial just makes everything on a type optional. This is great if you have an options object. Where you have maybe a set of defaults and someone can pass you a subset of those options.

[00:00:22] And you just wanna do sort of an object merge, like a big splat. So take whatever is given, merger it into my fallbacks and you have the full set of options. So Partial has put a question mark next to name and email, it may have email. Pick allows us to select one or more properties of something.

[00:00:48] So, I've created a type called HasThen, it takes a type parameter and it's going to pick of a promise, then, and catch. So let's see, so then I'm using the type, I'm extracting off of promise.resolve just, then, and catch. And so there they are, if I were to just grab then we would only see then.

[00:01:20] If I'd made this a little simpler,
>> Mike North: Then we don't need the template here.
>> Mike North: I didn't initialize it, but we can see only a is present,
>> Mike North: Only b should be present here, or you can do b or a and they should both be present. So you're picking off of an object type by property key.

>> Mike North: Extract lets us, when you have a big intersection type it'll let you select things that are assignable to a particular type. So give me only strings, I misnamed this here. Number, gives me only numbers.