1 00:00:00,120 --> 00:00:02,130 - This next built-in type is really simple. 2 00:00:02,130 --> 00:00:04,140 It's very similar to required and partial 3 00:00:04,140 --> 00:00:06,390 in that it just takes an entire object or type 4 00:00:06,390 --> 00:00:08,220 and it just manipulates the entire type 5 00:00:08,220 --> 00:00:09,840 to be one specific thing. 6 00:00:09,840 --> 00:00:12,060 Imagine we wanted to have like a final to do 7 00:00:12,060 --> 00:00:13,890 and this to do is one that cannot be changed. 8 00:00:13,890 --> 00:00:14,723 It's the final to do. 9 00:00:14,723 --> 00:00:15,840 It's like saved as is. 10 00:00:15,840 --> 00:00:17,400 Essentially, it's read only. 11 00:00:17,400 --> 00:00:20,310 Well, we can use a built-in read only type to do that. 12 00:00:20,310 --> 00:00:23,220 So we can say read only and pass it in our type, 13 00:00:23,220 --> 00:00:24,090 which is to do. 14 00:00:24,090 --> 00:00:24,990 And now, when we hover over here, 15 00:00:24,990 --> 00:00:27,930 you can see it marks every single property as read only. 16 00:00:27,930 --> 00:00:30,510 This is very similar to how as const works, 17 00:00:30,510 --> 00:00:33,750 but as const can only be used on JavaScript code 18 00:00:33,750 --> 00:00:35,760 and it cannot be used on TypeScript code. 19 00:00:35,760 --> 00:00:37,980 So I could say here that I have a to do, 20 00:00:37,980 --> 00:00:40,290 which is going to be of type to do 21 00:00:40,290 --> 00:00:43,860 I'm gonna set that equal to a to to do here real quick. 22 00:00:43,860 --> 00:00:45,900 And our completed is false. 23 00:00:45,900 --> 00:00:47,010 And now, if I hover over this, 24 00:00:47,010 --> 00:00:48,690 you can see it has that type of to do. 25 00:00:48,690 --> 00:00:51,090 Well, what I could do is I could set that as const, 26 00:00:51,090 --> 00:00:52,620 and now essentially, that's going to give me 27 00:00:52,620 --> 00:00:54,510 a read only version of my to do. 28 00:00:54,510 --> 00:00:56,730 I can just remove this typing here from it. 29 00:00:56,730 --> 00:00:59,130 And you can see, we get a read only version of this to do 30 00:00:59,130 --> 00:01:01,110 by using this as const property. 31 00:01:01,110 --> 00:01:02,790 It's the exact same thing as what happens 32 00:01:02,790 --> 00:01:05,010 when I use read only on the type itself. 33 00:01:05,010 --> 00:01:06,630 So if you wanna get the type of to do, 34 00:01:06,630 --> 00:01:11,460 I can even say here, type test equals type of to do, 35 00:01:11,460 --> 00:01:13,110 you can see that this test type right here 36 00:01:13,110 --> 00:01:14,880 is exactly the same as this final to do. 37 00:01:14,880 --> 00:01:16,086 They both do the exact same thing, 38 00:01:16,086 --> 00:01:19,440 as const is just what you use when you have JavaScript code 39 00:01:19,440 --> 00:01:20,760 and read only is what you have 40 00:01:20,760 --> 00:01:22,260 when you want to create a type 41 00:01:22,260 --> 00:01:24,990 from another type that you want to make read only. 42 00:01:24,990 --> 00:01:25,823 I'm gonna be honest, 43 00:01:25,823 --> 00:01:28,920 this isn't one that I find myself using too terribly often, 44 00:01:28,920 --> 00:01:31,140 but for example, there's a method in objects 45 00:01:31,140 --> 00:01:32,730 called object.freeze, 46 00:01:32,730 --> 00:01:34,830 and essentially, this makes an object immutable, 47 00:01:34,830 --> 00:01:36,420 so you can't change anything inside of it. 48 00:01:36,420 --> 00:01:37,920 And this essentially just returns to you 49 00:01:37,920 --> 00:01:39,780 a read only version of your type, 50 00:01:39,780 --> 00:01:41,490 so it's using that read only type 51 00:01:41,490 --> 00:01:43,410 to essentially define this if we can look at this. 52 00:01:43,410 --> 00:01:44,670 And if I scroll down a little ways 53 00:01:44,670 --> 00:01:45,810 to this freeze method here, 54 00:01:45,810 --> 00:01:47,040 here's a really simple version of it. 55 00:01:47,040 --> 00:01:47,970 You can see right here, 56 00:01:47,970 --> 00:01:50,070 it just returns a read only version of your object, 57 00:01:50,070 --> 00:01:51,210 so this is a really good use case 58 00:01:51,210 --> 00:01:53,700 for where that would be something that you would want to do. 59 00:01:53,700 --> 00:01:55,290 So again, it's not something you use all the time, 60 00:01:55,290 --> 00:01:57,840 but if you want to convert one type to a read only version 61 00:01:57,840 --> 00:01:58,890 of that same exact type, 62 00:01:58,890 --> 00:02:00,903 the read only built-in type is perfect.