Loading
Current section: 7. Interfaces 5 exercises
solution

Extending Interfaces

Transcript

00:00 Alright. Let's go. Let's make our interface, interface time stamps that has created at and updated at, and then we're going to use that to create an entity. So an entity is time stamps plus an ID. And then if we and if we hover over that, it literally just says interface entity.

00:16 This is one of the reasons I actually like prefer types. Sometimes types have errors or problems with the error messages too and those little pop ups. But anyway, yeah. Now we're going to take our interface user extends entity. So user is gonna have an ID plus the two time stamps and then it'll also have a name and an email.

00:36 And we'll do the same with products except that's gonna have a name and a price. We I suppose we could have a named entity and extend further there. We're gonna just extend like crazy. And then we'll make an audit log that has, just the time stamp. So no ID, just a time stamp, and the action and use user ID.

00:55 And And then we're gonna make a user based off of that. Here, let's make a user product. There we go. Come on. You know what I'm trying to do.

01:03 Do the rest of them. There we go. Awesome. Okay. Let's look at what all of this ends up being like.

01:08 So our user is just interface user. We are getting some type help. So if I were to do this is true, then it's gonna give us an error because it's not part of the user type or user interface. So like all of the same things apply and feel free to like play around with this. But it's all pretty straightforward.

01:27 You can also say, is employee true? And that's gonna say, no. You can't do that because it's not on the user interface. So, the user is comprised of entity which is comprised of the time stamps, and then it also has a name and an email. Product is, an entity which has the time stamps and the ID and a name and a price.

01:46 The audit log just has the time stamps and has action and user ID. So that's it. That's the entire thing. Hopefully, that was interesting and exciting for you. You of course, you can take a look at these, as well.

01:58 And, yeah. Let's, the the real question that I hope is your is going through your mind right now is, like, like, okay. So why would I use interfaces versus, types? That's like the big question in, in the TypeScript ecosystem too. A lot of people kinda disagree on when to use types versus interfaces.

02:16 We're gonna talk a little bit about when you would wanna use an interface in the next step. So we'll see you in the next one.