TypeScript Essentials: Functions & Objects | Extending the Interface

TypeScript
Transcript

English (Auto-generated)

thing and the intersection. So why we need the extending and what is the intersection first? Let's talk about the extending. Then we will be talking about the intersection. So um, for example, there is a person, there is a person you can see that um, which is, you know, which is which has a name, the height, the age and then let's say um, a few more properties we need to add. Um, let's say is a programmer. This is the old thing we have already discussed programmer. Okay. And uh it can be bullying now. We need this one here. So maybe the is a programmer after all, but maybe it is not. So we just, you know, we can say, I mean, you know, we can say things like that is a programmer copy and paste. And we're telling false just for this scenario. So we're telling, you know, it's not a programmer. So um, that's okay. But um, maybe, you know, we're talking about a graphic, you know, a bunch of graphic designers and the programmers. So we can say is a programmer. No, it's false because it's not a programmer. But maybe can be someone from the, you know, the real estate business. So this isn't even a question, I mean is a programmer or not is not even a question. So what we do in that case, I'm putting the question mark here. So now if you just don't put it, this is not even a question for the chassis because it's he does the real estate thing. So you know, this is not even a question if it's a he's a programmer or he may be a graphic designer because this is not even the field the mall in. So this is one possibility. You just can make it dynamic, I mean not dynamic but optional actually. So it would be the choice when we are creating the object to use or not. But there is one more interesting or in a in a in a in a unique way, you know, for example, is a graphic designer. So is a programmer maybe, you know, we just can make it optional. But let's remove this. Okay. And I'm creating another interface interface with that. That question. Um, I'm changing the question anyway, interface. Yeah. Um, is, let's say um, python deV Okay, I'm creating a new new one. And here is, is it? And here we can say true. I mean, sorry, bullying. Okay. I've created a new thing. So, um, if Shazia is or any object is a python deV, then we can use this class. I mean we can use this interface but you know, um, whoever is a python developer absolutely has a name has a height, has an age. So there is one possibility simply copy them and paste it here. So um is a python developer. So absolutely, it can be true or false and the names can be, you know, anything that hide in the age, but because we just need everything as it is in this interface. So you just can, you know, you just can go with this as I did and you just need to add a little things like, you know, extends, extends and then space person. Okay, So this is something, you know, now this is something um the person has everything, you know, every developer needs, I mean every developer has a name, has a height, has the age, but if it's a python developer, uh then uh we just created a new interface and if it's a python developer, then it needs this extra thing with all of them. So we we created this uh this new interface and we extended this new interface with the person. So now everything in the person is now the part of this interface. So, um if we just go down and we create let Person two and instead of assigning the person, I'm assigning Python Dev and equal to and I'm going down and inside and now is it true? Let's say true. But you know, when I have the mouse, you can see that it's missing. The following properties from type is python dev name, height and age. So it is literally telling that the name height and age are extended to inside this, you know, the python, they've extended with the person's properties and now these properties are missing. So you need to add them the person in the person to. So just need to add a line break and you need the right name and name. Can be anything like john okay. And it's still, if you just hover the mouse you know uh the following property is missing. He hide an age from the python dab even though we didn't add them but we extended everything from the person. So now you can use this scenario at anywhere wherever you want, name Hyatt and then the height I'm adding 5.7 And I'm going down and I'm writing a jazz 35 and let's say I make now there is no error, there is nothing wrong, everything is fine. But what if just I just make it a string. However the mouse, you can see that the string is not attainable to the type number. The expected type comes from property age which is declared here on type is Python. Okay. You can see that you just hover the mouse, you just clicked. You know, I just click here here is the expected type so which is declared on his python death. So if I just click here, it just selects age which is number. So it explains, it has to be a number. I think it is pretty much simple and understandable. The extending is you know it is here now we need to talk about the intersection and I think the, I need to talk about the intersection in the next video. So until then stay tuned
42 Views 0 Likes 0 Comments

We go over extending the interface in TypeScript.

Comment
Leave a comment (supports markdown format)