1 00:00:00,730 --> 00:00:04,690 In this video we're going to get a better idea of what this angle bracket syntax is really doing for 2 00:00:04,690 --> 00:00:05,250 us. 3 00:00:05,350 --> 00:00:09,190 If you are already familiar with TypeScript and understand what generics are you can skip over this 4 00:00:09,190 --> 00:00:10,010 video entirely. 5 00:00:10,030 --> 00:00:16,180 Otherwise stick around the angle bracket syntax we see right here is the generic syntax inside a typescript. 6 00:00:16,360 --> 00:00:22,010 You can really think of these generic things as essentially being functions or types. 7 00:00:22,030 --> 00:00:25,720 Let me give you an example right now when we call model. 8 00:00:25,930 --> 00:00:30,850 We've got a function invocation right here or the set of parentheses when we normally call a function 9 00:00:30,880 --> 00:00:32,500 inside of typescript or JavaScript. 10 00:00:32,500 --> 00:00:38,470 We pass in a set of arguments those arguments customize how that function behaves the same thing is 11 00:00:38,470 --> 00:00:42,760 true or this list of generic type arguments as well. 12 00:00:42,760 --> 00:00:48,280 You can really think of these as being some arguments to the function of model but instead of being 13 00:00:48,340 --> 00:00:54,370 a data type or an actual value like let's say a string of user or this user schema thing it is instead 14 00:00:54,430 --> 00:00:55,390 a type. 15 00:00:55,390 --> 00:01:01,110 So again you can think of these as being types being provided to a function as arguments to really get 16 00:01:01,110 --> 00:01:02,990 a better idea of what's going on behind the scenes. 17 00:01:03,030 --> 00:01:08,590 I'm going to hold down command on my keyboard and then click on model if you're on windows you probably 18 00:01:08,590 --> 00:01:14,260 want to hit control and then click instead that will take us to the definition of what the model function 19 00:01:14,260 --> 00:01:15,370 is. 20 00:01:15,400 --> 00:01:21,840 This is the typescript definition of that function not the actual javascript implementation so there 21 00:01:21,840 --> 00:01:28,310 is a function called model and we can optionally provide to generic types to it. 22 00:01:28,320 --> 00:01:31,290 So here is generic type number 1 and generic type. 23 00:01:31,290 --> 00:01:34,370 Number two I know the syntax in here is really crazy. 24 00:01:34,410 --> 00:01:38,490 All you really need to understand once again is that these re centrally arguments that we are providing 25 00:01:38,490 --> 00:01:43,000 to this function they are not arguments in the same sense as normal arguments to a function that are 26 00:01:43,000 --> 00:01:43,620 used to. 27 00:01:43,620 --> 00:01:50,840 Instead they are customizing types so if we go back over to where we hold model we provided two types. 28 00:01:50,840 --> 00:01:52,890 User dock end user model. 29 00:01:52,940 --> 00:02:01,910 So those are going to show up as argument won and argument to so argument one is referred to as t that 30 00:02:01,910 --> 00:02:08,770 named T right there is the same as though we had some kind of argument name such as name or schema. 31 00:02:08,870 --> 00:02:14,720 We also have a second type argument that's going to be called you we can take a look at the function 32 00:02:14,720 --> 00:02:20,090 definition and get a better understanding of how these different types are actually being used in particular. 33 00:02:20,090 --> 00:02:21,950 Let's take a look at you right here. 34 00:02:21,980 --> 00:02:27,770 You'll notice that that you type is being used down here at the very end remember that this syntax right 35 00:02:27,770 --> 00:02:32,850 here is referring to the type of value that the function of model is going to return. 36 00:02:32,870 --> 00:02:37,440 So this right here says that whenever we call model we're going to be returning type you. 37 00:02:37,580 --> 00:02:38,970 And what is type you. 38 00:02:39,020 --> 00:02:45,260 Well it's whatever we pass in as the second generic type argument to the model function in our case 39 00:02:45,350 --> 00:02:51,020 our second type argument is user model and that means that we are saying that the model function over 40 00:02:51,080 --> 00:02:54,350 all is going to return something of type. 41 00:02:54,350 --> 00:02:59,690 User model and so if I actually go back over to and hover over user right here it says that user is 42 00:02:59,690 --> 00:03:02,060 going to be uptime user model. 43 00:03:02,060 --> 00:03:07,730 If I change the second argument right here to anything else then the model function is going to return 44 00:03:07,790 --> 00:03:10,990 a value of type whatever I put in there. 45 00:03:11,000 --> 00:03:16,910 So for example if I type in any now typescript the typescript thinks that the model function is going 46 00:03:16,910 --> 00:03:19,790 to return a value of type any. 47 00:03:19,820 --> 00:03:26,530 And so if I go and take a look at what gets assigned to user now user is of type any as well okay. 48 00:03:26,580 --> 00:03:32,830 So going to revert that back over to user model so again this is referred to as generics in typescript. 49 00:03:32,830 --> 00:03:36,200 This is a very brief very brief summary of what they're all about. 50 00:03:36,210 --> 00:03:42,520 They essentially allow us to customize the types being used inside of a function a class or an interface. 51 00:03:42,520 --> 00:03:44,760 We don't only need to understand a lot more beyond that right now. 52 00:03:44,770 --> 00:03:49,570 I just want to give you a very quick understanding of what the stuff is being used for. 53 00:03:49,600 --> 00:03:49,850 OK. 54 00:03:49,900 --> 00:03:52,480 Let's take a quick pause here and continue in just a moment.