1 00:00:00,150 --> 00:00:02,310 - Now, hopefully, this code looks rather familiar 2 00:00:02,310 --> 00:00:04,020 since we've talked about this before. 3 00:00:04,020 --> 00:00:06,600 And the whole idea here is how you create an object, 4 00:00:06,600 --> 00:00:09,570 which has dynamic keys that have a specific value. 5 00:00:09,570 --> 00:00:11,880 For example, if you wanna group people by their name, 6 00:00:11,880 --> 00:00:13,410 you would have a key for each name, 7 00:00:13,410 --> 00:00:14,610 which in our case is a string. 8 00:00:14,610 --> 00:00:17,940 And then you're going to have the actual person array itself 9 00:00:17,940 --> 00:00:19,110 as the value. 10 00:00:19,110 --> 00:00:21,420 This is very common, and you may see this code all the time 11 00:00:21,420 --> 00:00:22,560 but there's actually multiple ways 12 00:00:22,560 --> 00:00:24,900 you can create this exact same signature. 13 00:00:24,900 --> 00:00:25,733 What we could do 14 00:00:25,733 --> 00:00:26,880 if we wanted to create the same exact thing, 15 00:00:26,880 --> 00:00:28,680 I'm just gonna copy this down so we can compare 16 00:00:28,680 --> 00:00:31,950 and contrast them is I can use the built-in record type. 17 00:00:31,950 --> 00:00:34,650 So this record type takes two generic types. 18 00:00:34,650 --> 00:00:36,540 The first one is the type for your key, 19 00:00:36,540 --> 00:00:38,250 which in our case is a string. 20 00:00:38,250 --> 00:00:40,620 So whatever you have set here, that's what that type is. 21 00:00:40,620 --> 00:00:41,730 And the second one is going 22 00:00:41,730 --> 00:00:43,680 to take whatever your actual value is. 23 00:00:43,680 --> 00:00:46,170 In our case, it is a person array. 24 00:00:46,170 --> 00:00:48,300 Now, this has the exact same signature. 25 00:00:48,300 --> 00:00:51,690 You can even see that it breaks down to the exact same code. 26 00:00:51,690 --> 00:00:53,550 This record type is essentially just an alias 27 00:00:53,550 --> 00:00:55,200 for doing this exact same thing. 28 00:00:55,200 --> 00:00:57,990 And personally, I find the record type a little bit easier 29 00:00:57,990 --> 00:01:00,210 to read than this index type up here. 30 00:01:00,210 --> 00:01:02,610 So I generally lean more towards the record type 31 00:01:02,610 --> 00:01:04,830 when I'm creating different signatures like this. 32 00:01:04,830 --> 00:01:05,820 I like how it looks 33 00:01:05,820 --> 00:01:08,850 and it's a really good way to create an object like this. 34 00:01:08,850 --> 00:01:09,780 And what could I even do 35 00:01:09,780 --> 00:01:11,370 if I wanted to be a little bit more specific, 36 00:01:11,370 --> 00:01:13,590 I could say this is the person name property 37 00:01:13,590 --> 00:01:15,570 'cause if I changed my name to a number or something, 38 00:01:15,570 --> 00:01:17,430 this would still work just fine. 39 00:01:17,430 --> 00:01:19,380 So this is a really great way to create objects 40 00:01:19,380 --> 00:01:21,090 instead of using this index type. 41 00:01:21,090 --> 00:01:22,680 Both of them do the exact same thing 42 00:01:22,680 --> 00:01:24,030 so it doesn't matter which one you use. 43 00:01:24,030 --> 00:01:24,863 I mean, you can see, 44 00:01:24,863 --> 00:01:27,360 they boil down to the exact same code in TypeScript. 45 00:01:27,360 --> 00:01:28,620 It's entirely a personal preference. 46 00:01:28,620 --> 00:01:29,520 I just prefer this one 47 00:01:29,520 --> 00:01:31,570 'cause I find it a little easier to read.