Transcript
00:00 Okay. Let's jump into this. So we've got this order management system, so we're gonna make an enum that is, order status enum. This looks a little bit like a type except there's no equals, so it looks a little bit more like an interface, but then there's these equal signs here. So it's just a completely different thing by itself.
00:16 These values can be strings. They can be numbers. They can be, billions of true and false. Just kidding. Can't be billions.
00:28 So really just a number or a string. That's your only option. Okay. Great. And there we go.
00:34 Keep on undoing and stuff. Alright. So then we can make an order. Let's actually make a type for order. So the status is gonna be one of those order statuses.
00:45 And so then when we make an order object, order order, there we go, we have our status right here. Now, you cannot cannot, just use the value of that, enum. You have to reference the enum itself. Also, yeah, not the name of the enum. That also doesn't work.
01:04 You have to use the order status, dot and then, the it'll give you a selection of these things. We're gonna say, pending. We don't need to ask order status. That works fine. Okay.
01:17 Great. So now, that we've got that, let's go ahead and we'll console log our order. Looks awesome. Let's make a get, status message thing that handles all of our different cases here and we'll console log that and also let's export our stuff here. And we've got our, status.
01:36 So your order is pending. Tada. It works just fine. I've got some some beef with enums that we're not gonna talk about here, but or we'll talk about one of them, and we'll cover the other one in our next step here. But, yeah.
01:52 The the big beef I have with this is if you take a look at the compiled code of, of this code here, then you'll see what it does, what TypeScript has to do to support enums. It's this piece right here. That maps to our, enum stuff right here. So, the reason I don't like this is because it's a TypeScript only feature that actually generates run time code. So this is the code that's actually going to run-in the browser or in whatever environment you're running your your, JavaScript in.
02:27 You write TypeScript, it compiles into this. But, everything else that's TypeScript only gets compiled away, just just disappears. So we've got our order status right here. That's gonna disappear. You've got your, let's see.
02:42 What else is specifically type yeah. Most of it's actually not TypeScript. Most of this is, here. Let's let's grab our example. There we go.
02:52 So we've got this order thing right here. That gets compiled away. So all the TypeScript specific stuff just goes away. I like that a lot. I I want TypeScript to be one thing and then all of the, the JavaScript stuff to just hang around and TypeScript just kinda melts away.
03:09 But enums are different. Enums will actually generate run time code, and I just don't like that. It feels it feels wrong. Feels wrong to me. I don't I'm not a huge fan of that.
03:18 So that's one reason that I don't like enums. The other reason is that, like, their benefits are annoying. So we'll look at that here in the next step. But, hopefully, this at least gives you a sense for how to use enums. You create it like this and then you reference it everywhere you go, so that you're able to, track where those things are being used.
03:42 Okay. Great. Well done on this one. We'll see you in the next.
