Loading
Current section: 7. Interfaces 5 exercises
solution

Object Shapes

Transcript

00:00 Alright. Let's go through this together now. We've got defining object shapes with interfaces. So we're gonna create a product interface with these properties. So interface product.

00:08 Here we've got our ID, name, price, status, and description. So, like, all of the same things, really work with interfaces as they do with types. In fact, we could very easily migrate this over to a type by simply saying type product and then equals. And these are foundationally or fundamentally the same product type here. There we go.

00:30 There's there's not a whole lot of difference. Now, there's slight differences in how you interact with them if you want to extend them or something like that, but for all intents and purposes, they are pretty much the same. So what is the point of doing interfaces versus types? So that's something we're gonna learn about in future steps. Let's go ahead and create a product summary function that's gonna take that product and there's the string.

00:51 That all should look very familiar to you, and we can create a sample product and use that product with a description. There we go. So we, can then call the here we go. Let's get call, here, console. Log get product summary for both of those products.

01:12 There we go. And we're all all set and good. And we can set those statuses. The statuses like all of this will be nice and type safe as well. So, it's it's nice.

01:23 It's very familiar. And, so the question is why do we use interfaces versus types? Well, first of all, interfaces were first. Types came a little bit later, but there are some subtle differences that we'll get into soon. Alright.

01:34 Hopefully, that was pretty straightforward. Let's get into the next one.