Transcript
00:00 Welcome to the types aliases exercise. In this exercise, you're gonna learn about making type aliases. You've done a little bit of this before if you've done it in some of the previous workshops, but I wanna formalize this and make sure that everybody's on the same page with what you can do with type aliases. So, here's what you have to do if you didn't have type aliases where if you wanted to type these, users as something specific, you'd have to duplicate yourself. Kind of repetitive.
00:25 Don't like that at all. So So you can simply make a type alias. It's kinda like declaring a variable except on the typescript side of things. So we're gonna be learning a little bit about that. You can also use type aliases for non, object things.
00:40 So here we've got an ID that's a string or a number. We'll look at, what this symbol is a little bit later in the workshop. You can specify it to be an array of exactly two items or a tuple, or you can, specify it to be a function, a function type. So it can be all types of types. And also, you can reference some types inside of other types, kind of like composing these objects together.
01:07 Inside of a function callback, you can destructure. So this would be a user object where we're gonna destructure that to get the address of the user object that's passed, and that's gonna return the address so it can be used as the return type as well. Typically, for myself, if the type that I'm, making is not, like a reusable type that needs to be used elsewhere like a user type would be, then I actually like to inline my type definition right along with the function, and then I'll destructure this and I find that works really well. So, yeah. Then we've also got the string or number.
01:44 We've got these, points and callback. All of this. This is what we're going to learn in this exercise. I hope you enjoy it. Let's get right into it.
