1 00:00:00,940 --> 00:00:03,250 In this video we're going to start to solve issue number two. 2 00:00:03,250 --> 00:00:03,970 Remember this. 3 00:00:03,970 --> 00:00:09,370 Issue number two was related to the fact that these set of properties that we pass in to create a new 4 00:00:09,370 --> 00:00:14,330 user document are different than the properties that actually exist on that document. 5 00:00:14,430 --> 00:00:20,750 Behind the scenes we might add in say a created at or in updated at property let's figure out how we're 6 00:00:20,750 --> 00:00:22,160 going to solve this. 7 00:00:22,250 --> 00:00:27,980 After that we'll then start to reflect on some that kind of strange syntax that we saw around that right 8 00:00:27,980 --> 00:00:28,370 there. 9 00:00:28,370 --> 00:00:31,990 And the any and the any right there OK. 10 00:00:32,020 --> 00:00:35,780 So to solve this issue issue number two we're gonna create a another interface. 11 00:00:35,920 --> 00:00:40,570 So after the two that we already put together I'm going to put another comment in here and say an interface 12 00:00:40,660 --> 00:00:50,300 that describes the properties that a user document has these interfaces. 13 00:00:50,300 --> 00:00:52,910 If you really sit down and read it they really make a lot of sense. 14 00:00:52,910 --> 00:00:56,690 We've got one that describes what it takes to create a user. 15 00:00:56,690 --> 00:01:02,930 We've got another one that describes what the entire collection of users looks like or least methods 16 00:01:02,930 --> 00:01:04,770 associated with the User model. 17 00:01:05,030 --> 00:01:11,950 And then an interface that describes what properties a single user has going to write out interface 18 00:01:13,550 --> 00:01:22,960 we're gonna call this one user Doc and I can say extents Mongoose dot document so once again we're gonna 19 00:01:22,980 --> 00:01:26,140 say that the definition of what a user document is. 20 00:01:26,270 --> 00:01:29,620 Make all the different properties that a normal document has. 21 00:01:29,880 --> 00:01:31,440 And we're going to add a couple more on top. 22 00:01:32,040 --> 00:01:37,260 So in this case we're gonna say that an instance of a user is going to have an email that is a string 23 00:01:38,010 --> 00:01:39,420 and a password that is a string 24 00:01:42,300 --> 00:01:45,400 so those are the properties that a single user has. 25 00:01:45,550 --> 00:01:50,620 If we ended up adding in additional properties or if Mongoose automatically added those properties in 26 00:01:50,800 --> 00:01:52,050 this is where we list them. 27 00:01:52,110 --> 00:01:54,740 So we would list out something like read it at. 28 00:01:54,760 --> 00:01:58,680 That's a string and updated at that is a string as well. 29 00:01:58,780 --> 00:02:02,530 But in our case we are not telling Mongoose to add in these properties for us right now. 30 00:02:02,590 --> 00:02:03,620 So I'm going to remove those. 31 00:02:03,640 --> 00:02:06,880 But again if we had those extra properties that is where we would add them 32 00:02:09,830 --> 00:02:10,160 OK. 33 00:02:10,210 --> 00:02:16,260 Now you put this together we're now going to take this interface and we're going to apply it down at 34 00:02:16,260 --> 00:02:16,860 the very bottom 35 00:02:19,710 --> 00:02:25,530 so where we are creating our user right here or the user model I can replace the any right there with 36 00:02:25,800 --> 00:02:30,410 user Doc I'm also going to go back up 37 00:02:33,470 --> 00:02:35,980 to where we defined the interface for user model. 38 00:02:36,140 --> 00:02:40,430 So we've now got an interface that describes what a single user looks like which means when we call 39 00:02:40,430 --> 00:02:45,110 built rather than returning any right here or saying that we are going to return any we're going to 40 00:02:45,110 --> 00:02:50,080 instead indicate that we are going to return an instance of a user or a user document it's going to 41 00:02:50,070 --> 00:02:59,030 replace that any with user Doc I'm going to replace the any right there with user doc as well. 42 00:02:59,130 --> 00:03:02,800 So let's now go down to the very bottom and we'll do a quick test. 43 00:03:02,920 --> 00:03:10,580 I'm going to once again create a new user by doing a user dot build and I'll pass in an email of whatever 44 00:03:12,410 --> 00:03:19,420 and a password of whatever to now if I hover over user right here I'm being told that I got back an 45 00:03:19,480 --> 00:03:27,180 instance of user duck it's now if I try to print out or access properties on here I can access things 46 00:03:27,180 --> 00:03:34,460 like user dot email I can also access user dot password if we do not have this interface correctly set 47 00:03:34,460 --> 00:03:38,910 up user dock right here we would not be allowed to access these properties safely. 48 00:03:38,910 --> 00:03:44,100 So for example let's say that we actually did want to add in this idea of a created that time or created 49 00:03:44,400 --> 00:03:49,320 or updated that time if we write out to user dot updated at typescript is going to complain and say 50 00:03:49,530 --> 00:03:54,240 hey that property doesn't exist even if we know that that mongoose is going to add in this property 51 00:03:54,270 --> 00:03:55,740 automatically for us. 52 00:03:55,910 --> 00:04:00,010 So to tell typescript that hey it's OK if we want to access the thing oh you'd have to do. 53 00:04:00,030 --> 00:04:07,690 Again go back up to the user dock interface and say updated at is going to be a string like so and if 54 00:04:07,690 --> 00:04:12,460 we go back down now that error has gone away OK. 55 00:04:12,510 --> 00:04:12,950 So that's it. 56 00:04:12,950 --> 00:04:21,090 That's how we solve issue number two it's gonna delete this extra stuff right here I'm gonna go back 57 00:04:21,090 --> 00:04:22,910 up to the interface and delete that. 58 00:04:22,920 --> 00:04:27,190 Updated at and save the file. 59 00:04:27,260 --> 00:04:28,620 We're going to take a quick pause right here. 60 00:04:28,640 --> 00:04:33,980 When we come back in the next video one last thing I want to discuss what is the goal of these little 61 00:04:33,980 --> 00:04:35,090 brackets right here. 62 00:04:35,150 --> 00:04:40,560 So down on Mongoose top model also up here and I think that was the only other location. 63 00:04:40,580 --> 00:04:42,780 So what's the goal of those little angled brackets. 64 00:04:43,010 --> 00:04:47,210 This is going to be a lecture that's mostly just about typescript because this really is some typescript 65 00:04:47,210 --> 00:04:48,180 syntax right here. 66 00:04:48,200 --> 00:04:51,590 I want to give you a little bit of backstory on what the goal of those things are and why we had to 67 00:04:51,590 --> 00:04:52,100 add them in.