Loading
Current section: 4. Intersection Types 3 exercises
solution

Combining Types

Transcript

00:00 Okay. Let's get into it. So we've got combining types with intersection. We're gonna make these three types. So type with ID is gonna have an ID, the with time stamps and with author.

00:10 And so these are, the some of the primitive things that we're gonna need for the other types that we're gonna make. Let me just put all these on one string because I like the way that looks better. Yep. There we go. It's just They're kinda short, so let's just put them all in one string.

00:26 Alright. Sweet. So with that then, we can create a user that combines all of the types that users need. So ID and time stamps, along with some specific user only types. So name and string and email, or name, which is a string and the email.

00:41 And then we can do the same for the post and same for a comment. And, bam. All all there it all is. Right there. Let's go ahead and review that.

00:50 Make sure that this is doing what we want it to and get rid of all these extra lines and stuff. Okay. So users, with ID, time stamps, and, name and email. Post has the ID and the time stamps that I have created at and updated at, and the author, author ID, and author name, as well as the title and content. And then a comment has an ID, time stamps, author, and text and post ID.

01:14 So what which post is it associated to? K. Alright. Sweet. So then let's create each of these types, make sure that these types make sense.

01:22 So a example of a user would be, ID of one, created at of the current day and, updated at would be currently. And then a name and email, a post has those things as well as author ID and name and the post specific properties. And then a comment also has, all of those things as well as a text and a post ID. So that is union types. You you can definitely go wild on this.

01:48 You could do all sorts of combinations and stuff. I don't typically go quite this wild. The with ID type probably isn't all that useful. I would just put an ID on each one of them. I don't know.

02:00 Maybe. But, yeah. I I might actually combine with ID and with time stamps to be like entity because every entity needs an ID and time stamps, something like that. But, hopefully, you get the idea of taking these different types, combining them together into making, one full type that has all of the things. Alright.

02:21 Great. Let's move on to the next.