Now we've completed our initial implementation of our user.
We can try to actually make use of it inside of our index dot test file in general anytime we create
a file that houses a single class and typescript we're not going to have any actual code in here that
does anything with the class.
Instead we will usually import this class into some other more central location and use it from there.
So in order to get access to this class inside of our index dot t test file we first have to export
it.
So to make the class available somewhere else inside of our project I can put the export keyword in
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
console log really quick.
We can write out import a set of curly braces and then user from the user file.
Now if you're coming from a background of GI react J.S. chances are the syntax looks really familiar.
Once again we are going to look into the user file.
We're going to find something inside there called user and pull it into the index not t s file as a
variable called User.
Notice how we've got the curly braces on here.
We have a very quick aside on what those curly braces are doing for us.
So anytime that we export something from a file using just the export keyword by itself we will always
receive that in another file by placing that word inside of a set of curly braces.
We do this so that we can safely export multiple different variables from this file.
So for example if we had another variable inside of here that we wanted to export it like let's say
a variable called red.
There was literally just a string red I can now import this into index dot T.S. by adding it as an additional
thing that we want to import from user
once again if you're coming from the world of react the syntax might seem a little bit strange because
in the react world we typically will export things using the default keyword the default keyword is
available inside of typescript as well.
If you haven't used the default keyword totally fine.
Let's take a look at how it works really quickly.
So right now we've seen an example of how we can export very specific variables from a given file.
However we can choose to also export something as the default export from a file as well.
So I could say export default and then just a single value by itself.
So in this case I did not provide a name for this value I'm trying to export.
Previously I had given it a name of red which means I could import it into another file as the name
Red.
But this time it's literally just the string red by itself so to import this value into another file
I would write out no curly braces and just the name of the thing I want to pull in.
So now red would be that string read this name right here it can actually be any variable we want to
call it.
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
did a console log of that we would see literally just a string red that's it in typescript we usually
do not use these default statements like the one you see right here.
The reason for that is that when you're first getting started with these modules like this in your statement
and this expert statement right here it gets really confusing really quickly when you should use curly
braces and when you shouldn't.
So convention inside of typescript is to never use default export statements.
Now of course there will be some people out there who disagree and who want to still use default default
statements.
If you work on a project where that is the case and you want to use default statements totally fine.
All I'm saying is that in the typescript world it's a little bit more community convention to not use
default exports and once again the reason for that is that then we don't have to worry about whether
or not we have to include those curly braces so if I don't have any default exports whatsoever that
means every time I import any code that is mine I'm always going to put on those curly braces.
So it just makes it really easy for me to remember and avoids simple little typos.
Now of course that rule does not apply to third party modules so NPM modules we use might still have
a default export statement as is the case with faker right here and that's totally fine.
It is unavoidable nonetheless.
The rule for us for code that we write is that we will avoid default statements if we can get.
That's a lot on default exports and all that kind of good stuff.
So last thing now that we've got the user inside of our index start to as file let's tried to use it
to create a new instance of a user and then just console log out that user like so all right now that
I've got that I'll flip back over to my terminal.
I've already got a library load here and you'll see that I've got a console log of my user.
So they have a name and a location that is an object with the latitude and longitude property as well.
Perfect.
All right so now we've got our user all put together and we can access them inside of our index dot
to yes file.
We're not gonna repeat this whole same process for a company as well.
It's a quick pause and I'll see you in just a minute.