Loading
Current section: 6. Conditional Types 4 exercises
lesson

Intro to Conditional Types

Loading lesson

Transcript

00:00 Alright. Now, we're gonna get to some pretty advanced conditional types. This is going to be a lot of fun. If you don't like ternaries, you're not gonna like it here. We're using ternaries here a lot.

00:10 And everything here, really relies on this extends. What this effectively does is it's saying, does this type match this type? Is the effectively, is this type wider than the type that I've been given, as wide or wider than the type I've been given? And so the syntax is, pretty simple. One type extends another type.

00:30 Then here's the, what the type should be in the true case. Otherwise, here's what the type should be in the false case. Some practical examples of this. You've got your, return type, statement here. We're using this infer keyword that we're gonna talk about.

00:44 Here's unwrapping a promise, very simple case. Awaited is a lot better. We'll talk about that a little bit. We're gonna grab only the strings. So if the type is not a string, then we're gonna, that's gonna end up in never, which allows you to kind of chain some of these expressions.

00:59 Pretty interesting. And then we can take these, this, ticket and filter out, only those that are priority high. And so that can be pretty helpful, pretty interesting. And like I said, we're gonna talk about the infer keyword as well. It's pretty advanced stuff.

01:17 These are things that I do not do every day. But, I use libraries that use this every day, and that's what makes them so powerful. So, here we are. We're in the advanced typescript workshop. I hope you love it and we'll see you in the exercise.