Loading
Current section: 6. Generics 5 exercises
Problem

Constraints

Loading exercise

Transcript

00:00 Alright. Now we're gonna get into some more advanced use cases for generics. Sometimes, the generics that we have so far are, too limiting because they're not limiting. So when you just take a generic value, as a function argument, from there, you have to then, like, do a bunch of checks if you wanna do anything useful with that value because you don't know what it is. It's known only at call time, but not in the body of the function.

00:25 And so what you can do instead is you can constrain the, the valid types that can be passed to your function so that only certain types can be, passed, and then you know that though that certain properties are available on the, types that are passed to you. This is really helpful, in a lot of scenarios. We're gonna be using, some basics of this, but then we're gonna get to some more little advanced, things in here. I think you're actually gonna really love this one. So let's jump into it, and we'll see you when you're done.