1 00:00:01,670 --> 00:00:04,700 Now we've completed our initial implementation of our user. 2 00:00:04,700 --> 00:00:10,310 We can try to actually make use of it inside of our index dot test file in general anytime we create 3 00:00:10,340 --> 00:00:15,680 a file that houses a single class and typescript we're not going to have any actual code in here that 4 00:00:15,680 --> 00:00:17,560 does anything with the class. 5 00:00:17,570 --> 00:00:23,570 Instead we will usually import this class into some other more central location and use it from there. 6 00:00:23,570 --> 00:00:28,880 So in order to get access to this class inside of our index dot t test file we first have to export 7 00:00:28,880 --> 00:00:29,500 it. 8 00:00:29,530 --> 00:00:34,070 So to make the class available somewhere else inside of our project I can put the export keyword in 9 00:00:34,070 --> 00:00:40,380 front of it like so then inside of index dot t s at the very top of the file I'm going to delete that 10 00:00:40,380 --> 00:00:41,640 console log really quick. 11 00:00:41,880 --> 00:00:49,340 We can write out import a set of curly braces and then user from the user file. 12 00:00:49,350 --> 00:00:54,930 Now if you're coming from a background of GI react J.S. chances are the syntax looks really familiar. 13 00:00:54,930 --> 00:00:58,030 Once again we are going to look into the user file. 14 00:00:58,110 --> 00:01:03,720 We're going to find something inside there called user and pull it into the index not t s file as a 15 00:01:03,720 --> 00:01:05,800 variable called User. 16 00:01:05,940 --> 00:01:07,830 Notice how we've got the curly braces on here. 17 00:01:07,860 --> 00:01:12,110 We have a very quick aside on what those curly braces are doing for us. 18 00:01:12,150 --> 00:01:18,180 So anytime that we export something from a file using just the export keyword by itself we will always 19 00:01:18,240 --> 00:01:23,940 receive that in another file by placing that word inside of a set of curly braces. 20 00:01:23,970 --> 00:01:28,750 We do this so that we can safely export multiple different variables from this file. 21 00:01:28,770 --> 00:01:32,820 So for example if we had another variable inside of here that we wanted to export it like let's say 22 00:01:32,820 --> 00:01:34,020 a variable called red. 23 00:01:34,020 --> 00:01:41,160 There was literally just a string red I can now import this into index dot T.S. by adding it as an additional 24 00:01:41,160 --> 00:01:43,590 thing that we want to import from user 25 00:01:46,660 --> 00:01:52,000 once again if you're coming from the world of react the syntax might seem a little bit strange because 26 00:01:52,000 --> 00:01:57,580 in the react world we typically will export things using the default keyword the default keyword is 27 00:01:57,580 --> 00:01:59,100 available inside of typescript as well. 28 00:01:59,200 --> 00:02:01,290 If you haven't used the default keyword totally fine. 29 00:02:01,300 --> 00:02:03,790 Let's take a look at how it works really quickly. 30 00:02:03,800 --> 00:02:10,310 So right now we've seen an example of how we can export very specific variables from a given file. 31 00:02:10,310 --> 00:02:14,800 However we can choose to also export something as the default export from a file as well. 32 00:02:14,810 --> 00:02:19,700 So I could say export default and then just a single value by itself. 33 00:02:20,360 --> 00:02:25,410 So in this case I did not provide a name for this value I'm trying to export. 34 00:02:25,610 --> 00:02:30,470 Previously I had given it a name of red which means I could import it into another file as the name 35 00:02:30,470 --> 00:02:31,120 Red. 36 00:02:31,250 --> 00:02:37,000 But this time it's literally just the string red by itself so to import this value into another file 37 00:02:37,540 --> 00:02:43,140 I would write out no curly braces and just the name of the thing I want to pull in. 38 00:02:43,230 --> 00:02:48,160 So now red would be that string read this name right here it can actually be any variable we want to 39 00:02:48,160 --> 00:02:48,480 call it. 40 00:02:48,490 --> 00:02:55,830 So I could call it red or I could call it color or user color or whatever we want it to be if we then 41 00:02:55,830 --> 00:03:03,540 did a console log of that we would see literally just a string red that's it in typescript we usually 42 00:03:03,540 --> 00:03:07,250 do not use these default statements like the one you see right here. 43 00:03:07,320 --> 00:03:12,480 The reason for that is that when you're first getting started with these modules like this in your statement 44 00:03:12,480 --> 00:03:17,010 and this expert statement right here it gets really confusing really quickly when you should use curly 45 00:03:17,010 --> 00:03:19,050 braces and when you shouldn't. 46 00:03:19,050 --> 00:03:24,000 So convention inside of typescript is to never use default export statements. 47 00:03:24,000 --> 00:03:29,220 Now of course there will be some people out there who disagree and who want to still use default default 48 00:03:29,220 --> 00:03:30,060 statements. 49 00:03:30,150 --> 00:03:35,290 If you work on a project where that is the case and you want to use default statements totally fine. 50 00:03:35,310 --> 00:03:40,110 All I'm saying is that in the typescript world it's a little bit more community convention to not use 51 00:03:40,320 --> 00:03:45,730 default exports and once again the reason for that is that then we don't have to worry about whether 52 00:03:45,730 --> 00:03:52,720 or not we have to include those curly braces so if I don't have any default exports whatsoever that 53 00:03:52,720 --> 00:03:58,060 means every time I import any code that is mine I'm always going to put on those curly braces. 54 00:03:58,060 --> 00:04:03,710 So it just makes it really easy for me to remember and avoids simple little typos. 55 00:04:03,740 --> 00:04:10,280 Now of course that rule does not apply to third party modules so NPM modules we use might still have 56 00:04:10,310 --> 00:04:14,780 a default export statement as is the case with faker right here and that's totally fine. 57 00:04:14,780 --> 00:04:16,730 It is unavoidable nonetheless. 58 00:04:16,730 --> 00:04:22,850 The rule for us for code that we write is that we will avoid default statements if we can get. 59 00:04:22,870 --> 00:04:26,110 That's a lot on default exports and all that kind of good stuff. 60 00:04:26,110 --> 00:04:31,060 So last thing now that we've got the user inside of our index start to as file let's tried to use it 61 00:04:31,060 --> 00:04:40,530 to create a new instance of a user and then just console log out that user like so all right now that 62 00:04:40,530 --> 00:04:42,700 I've got that I'll flip back over to my terminal. 63 00:04:42,780 --> 00:04:46,660 I've already got a library load here and you'll see that I've got a console log of my user. 64 00:04:46,680 --> 00:04:52,740 So they have a name and a location that is an object with the latitude and longitude property as well. 65 00:04:52,800 --> 00:04:53,990 Perfect. 66 00:04:54,030 --> 00:04:58,170 All right so now we've got our user all put together and we can access them inside of our index dot 67 00:04:58,170 --> 00:04:59,020 to yes file. 68 00:04:59,100 --> 00:05:03,070 We're not gonna repeat this whole same process for a company as well. 69 00:05:03,090 --> 00:05:05,390 It's a quick pause and I'll see you in just a minute.