In the last video, we installed a type definition file for Fakher as a quick side, one of those benefits
of type definition files is that we can now hover over Fakher right here.
And then if you're on Mac, hold down the command key or if you're on windows, hold down control.
You'll notice that Fakher turns into a clickable link of sorts.
If we now click on that, we'll be taken to the type definition file that we just installed.
Notice how the name of this file is indexed Deetz.
Traditionally type definition files are named with extensions of deetz.
So any time you are looking at some typescript code and you see a file with that extension, that means
you are looking at a type definition file.
Inside this file, you're going to find nothing but typescript syntax, so the only goal of this file
right here is to describe the different types of values, functions, objects, classes that exist inside
the FAKHER Library.
So there will not actually be any functions that are implemented inside of here.
Instead, instead, you will only see a definition of the different types that are available.
If you look inside of here, we can actually use this as a source of documentation.
So, for example, remember at the official documentation we looked at just a moment ago, we saw that
address module.
So this right here is telling TypeScript that this library has a address object and inside of it are
different functions like zip code, city, city prefix and so on.
We can see the different arguments that each of them take and the different type of values that they
return.
So like I said, we can use this file as kind of an alternate forms of documentation to understand how
to work with a given library.
So in this case, we can take a look at address, if we scroll down, you'll notice the latitude and
longitude are two functions inside there and we're going to use those functions to actually randomly
generate our latitude and longitude.
As a quick side note, I want you to notice how latitude, longitude, return strings, which is actually
kind of not very typical.
Usually we reflect the latitude and longitude as numbers.
So having them being returned here as a string means that might be a little bit unexpected.
And we might have to deal with that at some point in time, but we'll just see what happens.
All right.
So I'm going to close this file.
And back inside of my user daughter's file, we're not going to do some initialization of our name,
latitude and longitude inside of our constructor.
So inside the constructor, as soon as we make an instance of a user, we're going to randomly generate
a name and assign it to that name property.
So inside of your I'll say this DOT name is going to come from FACHER.
We're going to get the name module.
Remember, we saw that in the official documentation here, his name right here.
And we're going to generate a first name.
Once again, we could find the existence of this function either by looking at the official documentation
or just command clicking on Fakher and then search this thing for like first name.
And there it is, so here's the name module, there's the first name method, even by looking at this
documentation right here or this type definition file.
You'll notice that we even are told that we can take in a gender argument right here.
This actually did not exist in the official documentation.
So the type definition file actually gives us more information sometimes than he typed or submitted
documentation document actually does.
All right, so now we've generally the first name, we can do the same thing for our latitude and longitude
as well.
Now, here's a really quick note for you.
Something that really gets people hung up when they are getting started with typescript.
At this point, we have only till told TypeScript that our class user is going to be of type or going
to have a property called location and location will have an object with a latitude and longitude property.
Here's the important thing, when we create an instance of a user location does not get automatically
set to be an object.
So in other words, if we did right here a console log of this DOT location, we would see undefined
or null.
That means that if we tried to do direct assignment to latitude and longitude like this dot location,
that equals some number, we would actually see an error message and would say something like cannot
read property of Latt of undefined.
So all we have done up here is said, hey, typescript, we're going to have a location property, it
will be an object that has these two properties, but we have not done any initialization for that yet.
There is no object here when we create our user.
So we are responsible for initialization of this object and the properties inside of it.
So in other words, that means to initialize latitude and longitude.
We have to say this dot location is going to be an object with properties LAT and LNG.
So we can try to initialize both Latin LNG will do Fakher address, not lattitude.
I'll get a comma at the end of that line and then fakher dot address, dot longitude like so.
Even then, I still see an error message if we mouseover this.
You'll notice that it says.
Expected right here, type string is not assignable to type No.
So remember when we were looking at the documentation for the latitude and longitude or the type definition
filed just a second ago, we saw the latitude and longitude where functions that returned strings,
but we clearly said that latitude and longitude were going to be numbers.
Once again, in my opinion, this is kind of an oversight by the Fakher people and they really should
be returning numbers here.
However, that's just how they built this library.
So we need to take the strings that are returned by latitude and longitude and convert them into numbers.
To do so, we have to do an actual conversion process like this is a string right here.
So we have to convert that into an actual number.
So to do so, we're going to take a very JavaScript style approach.
We're going to use the pass float function just to make sure you are aware the passport function is
built into JavaScript.
It takes a string and returns a number that has a decimal value attached to it.
So we can call parts float on both.
And the air goes away because now we are signing a no to both latitude and longitude.
All right, so that's pretty much it.
Let's take a quick pause right here.
When we come back, the next video we're going to start to actually make use of our class.
So we'll see you in just a minute.