TypeScript Essentials: Functions & Objects | Custom Type Objects

TypeScript
Transcript

English (Auto-generated)

for the object here, but it looks kind of messy. But there is one more simple solution where you can define the custom type for this object. I mean it would be nearly similar but in a, you know, in a proper manner. So what you can do, I'm just going down and I'm going to create a new object and the new object can be anything. I'm making it a computer just, you know, whatever I thought in my mind so equal to and then, you know, because it's a computer. So the hard drive or let's say hard, sorry, hard drive. Okay. And I'm putting the value for the hard drive is uh um one TB. Okay, that's awesome. Now I'm talking about the next one RAM. It's gonna be the, you know, 32 Kotb. Okay. And then I'm going down and after the RAM um the the graphic card or you can say the G and G. F is not a very interesting word. G card suits anyway. Okay. The graphic art is for G. B. Okay. Um let's just make the G. Capital and the T capital sounds good. Okay. Now are vegetarian properties, three values. And then down here, um um what more we can put mm hmm. Article mouse. So it is true. I mean, or let's say not the optical one because almost every mouse's optical nowadays, let's say, you know, wireless mouse. So yeah, true. The wireless mouse. This is the wireless mouse. Okay. And um what more let's say the price of the computer. The prize. And here I'm gonna use some number. And I'm putting 500 let's say $500. Okay. That's awesome. And that's understandable because this is a simple object we've created. But now one method, you know you just simply can, you know, you can just go there which you've practiced perfectly. You just can go there and you can you know, you can define the the everything of the object inside here. But there is one more interesting way which is just simply be here and create type. Okay. And uh computer. Okay. And uh now here hard drive. It should be a strain. Okay RAM. It should be string Okay. G card. It should be strained wireless sorry, via wireless mouse. It should be fully in. Okay. And cries. It should be number. All awesome. All perfect. Now. Now, you know, you can do one thing that you can simply you know, you can simply copy all this data and actually all this data and copy that and paste it here. Let's just try this by just doing that. You know, it would work the same and you can see that you're not gonna have any problem unless you know we do something like just showing you we do something like that. So we're gonna have problems. This is this works fine. But there is one more better way. I'm just simply going to sign the computer with this one. Now this is separate. You know here almost nearly the same same way. But just one change that you can see that um in this way um What is exactly happening here is, Yeah, is this type is different and it can be defined anywhere instead of just you know doing this way. This looks awkward. So there is nothing different but you know because it's typescript so it's more documented. So this is the way to document it, document your object using the custom type. You just learned a new thing and you now know how to deal with these things. Let's just try if it still works the same. Yeah, you can see that. We just got the problem type string is not assign, able to type numbers because you know it's following this type which is here we've defined. Okay, so in the next video we're going to talk about something more until then stay tuned.
61 Views 0 Likes 0 Comments

We go over the concept of 'custom type' objects.

Comment
Leave a comment (supports markdown format)