Transcript
00:00 Alright. Welcome to the literal types exercise. I'm very excited about this one because I use as const all the time. And I really, really like deriving types out of the variables that I'm creating for my run time. So, here is an example of using as const and type of and, selecting different types.
00:19 These are all things that we're gonna be doing in this exercise. Couple of interesting things going on here. So we've got this array and locales is just gonna be an array of strings. That's all. And if we do type of locales and, select each, item to, like, create a union out of that, this locale type is just gonna be a string.
00:39 That's all it knows. It's an array of strings. This takes it and says, what is this an array of? That's effectively what's going on here. And it would just be, well, it's an array of strings.
00:47 That's all. But by adding as const, it can say, oh, it's an array with the first one being e n u s, then e s e s, and then f r f r. And so then when we say, what is this an array of? It says, oh, well, it's an array of e n e u s, e s, e s, and f r f r. So it makes it a lot more powerful and like specific.
01:08 It also makes it so we can't modify the locales which could be so we can't like push onto it and stuff, which can be really useful as well to avoid like somebody changing your object unknowingly. And that makes the utilities that you write a lot more useful as well when people are calling them and they know exactly what to call them with. It's more than just a string. It can only be one of these things. So that's part of the type narrowing stuff here as well.
01:35 And we also have another example using that with objects and, pretty much the same sort of idea. We'll talk about how type of takes something that's from the runtime world and brings it into the typing world. Key of is a special typescript feature that'll get you the keys of a particular type and then you can use type of, shortcuts with those keys to get the values. So it's kinda like object dot values and object dot keys. That's kinda what we're doing here, which kinda just thought of that just now.
02:05 So, anyway, I think you're gonna have a good time with this one. So let's jump into it. We'll see you in the exercise.
