1
00:00:00,850 --> 00:00:06,190
In the last video, we installed a type definition file for Fakher as a quick side, one of those benefits

2
00:00:06,190 --> 00:00:10,420
of type definition files is that we can now hover over Fakher right here.

3
00:00:10,660 --> 00:00:14,920
And then if you're on Mac, hold down the command key or if you're on windows, hold down control.

4
00:00:15,430 --> 00:00:18,580
You'll notice that Fakher turns into a clickable link of sorts.

5
00:00:19,150 --> 00:00:23,500
If we now click on that, we'll be taken to the type definition file that we just installed.

6
00:00:24,370 --> 00:00:27,850
Notice how the name of this file is indexed Deetz.

7
00:00:28,360 --> 00:00:32,729
Traditionally type definition files are named with extensions of deetz.

8
00:00:33,250 --> 00:00:37,690
So any time you are looking at some typescript code and you see a file with that extension, that means

9
00:00:37,690 --> 00:00:39,910
you are looking at a type definition file.

10
00:00:40,880 --> 00:00:46,430
Inside this file, you're going to find nothing but typescript syntax, so the only goal of this file

11
00:00:46,430 --> 00:00:52,490
right here is to describe the different types of values, functions, objects, classes that exist inside

12
00:00:52,490 --> 00:00:53,320
the FAKHER Library.

13
00:00:53,930 --> 00:00:57,630
So there will not actually be any functions that are implemented inside of here.

14
00:00:57,980 --> 00:01:02,540
Instead, instead, you will only see a definition of the different types that are available.

15
00:01:03,500 --> 00:01:07,040
If you look inside of here, we can actually use this as a source of documentation.

16
00:01:07,460 --> 00:01:11,960
So, for example, remember at the official documentation we looked at just a moment ago, we saw that

17
00:01:11,960 --> 00:01:12,920
address module.

18
00:01:13,400 --> 00:01:19,550
So this right here is telling TypeScript that this library has a address object and inside of it are

19
00:01:19,550 --> 00:01:23,720
different functions like zip code, city, city prefix and so on.

20
00:01:24,470 --> 00:01:28,550
We can see the different arguments that each of them take and the different type of values that they

21
00:01:28,550 --> 00:01:29,030
return.

22
00:01:29,630 --> 00:01:35,240
So like I said, we can use this file as kind of an alternate forms of documentation to understand how

23
00:01:35,240 --> 00:01:36,590
to work with a given library.

24
00:01:37,590 --> 00:01:42,780
So in this case, we can take a look at address, if we scroll down, you'll notice the latitude and

25
00:01:42,780 --> 00:01:47,310
longitude are two functions inside there and we're going to use those functions to actually randomly

26
00:01:47,310 --> 00:01:48,900
generate our latitude and longitude.

27
00:01:49,880 --> 00:01:54,860
As a quick side note, I want you to notice how latitude, longitude, return strings, which is actually

28
00:01:54,860 --> 00:01:56,520
kind of not very typical.

29
00:01:56,540 --> 00:01:59,890
Usually we reflect the latitude and longitude as numbers.

30
00:02:00,620 --> 00:02:04,880
So having them being returned here as a string means that might be a little bit unexpected.

31
00:02:04,880 --> 00:02:08,570
And we might have to deal with that at some point in time, but we'll just see what happens.

32
00:02:09,350 --> 00:02:09,680
All right.

33
00:02:09,680 --> 00:02:10,759
So I'm going to close this file.

34
00:02:12,000 --> 00:02:16,740
And back inside of my user daughter's file, we're not going to do some initialization of our name,

35
00:02:16,990 --> 00:02:19,500
latitude and longitude inside of our constructor.

36
00:02:20,240 --> 00:02:24,630
So inside the constructor, as soon as we make an instance of a user, we're going to randomly generate

37
00:02:24,630 --> 00:02:26,760
a name and assign it to that name property.

38
00:02:27,590 --> 00:02:33,050
So inside of your I'll say this DOT name is going to come from FACHER.

39
00:02:33,510 --> 00:02:35,500
We're going to get the name module.

40
00:02:35,520 --> 00:02:38,400
Remember, we saw that in the official documentation here, his name right here.

41
00:02:39,090 --> 00:02:41,760
And we're going to generate a first name.

42
00:02:43,330 --> 00:02:47,860
Once again, we could find the existence of this function either by looking at the official documentation

43
00:02:47,890 --> 00:02:53,800
or just command clicking on Fakher and then search this thing for like first name.

44
00:02:55,770 --> 00:03:01,290
And there it is, so here's the name module, there's the first name method, even by looking at this

45
00:03:01,290 --> 00:03:03,480
documentation right here or this type definition file.

46
00:03:03,630 --> 00:03:07,780
You'll notice that we even are told that we can take in a gender argument right here.

47
00:03:08,280 --> 00:03:10,830
This actually did not exist in the official documentation.

48
00:03:10,830 --> 00:03:15,930
So the type definition file actually gives us more information sometimes than he typed or submitted

49
00:03:15,930 --> 00:03:17,910
documentation document actually does.

50
00:03:19,450 --> 00:03:24,730
All right, so now we've generally the first name, we can do the same thing for our latitude and longitude

51
00:03:24,730 --> 00:03:25,150
as well.

52
00:03:25,810 --> 00:03:27,310
Now, here's a really quick note for you.

53
00:03:27,310 --> 00:03:31,060
Something that really gets people hung up when they are getting started with typescript.

54
00:03:31,720 --> 00:03:38,050
At this point, we have only till told TypeScript that our class user is going to be of type or going

55
00:03:38,050 --> 00:03:44,110
to have a property called location and location will have an object with a latitude and longitude property.

56
00:03:45,460 --> 00:03:51,400
Here's the important thing, when we create an instance of a user location does not get automatically

57
00:03:51,400 --> 00:03:52,830
set to be an object.

58
00:03:53,530 --> 00:03:59,920
So in other words, if we did right here a console log of this DOT location, we would see undefined

59
00:03:59,920 --> 00:04:00,580
or null.

60
00:04:01,300 --> 00:04:06,010
That means that if we tried to do direct assignment to latitude and longitude like this dot location,

61
00:04:06,310 --> 00:04:11,560
that equals some number, we would actually see an error message and would say something like cannot

62
00:04:11,560 --> 00:04:13,810
read property of Latt of undefined.

63
00:04:14,850 --> 00:04:19,500
So all we have done up here is said, hey, typescript, we're going to have a location property, it

64
00:04:19,500 --> 00:04:25,960
will be an object that has these two properties, but we have not done any initialization for that yet.

65
00:04:25,980 --> 00:04:28,790
There is no object here when we create our user.

66
00:04:29,430 --> 00:04:36,130
So we are responsible for initialization of this object and the properties inside of it.

67
00:04:36,810 --> 00:04:40,230
So in other words, that means to initialize latitude and longitude.

68
00:04:40,230 --> 00:04:47,760
We have to say this dot location is going to be an object with properties LAT and LNG.

69
00:04:49,100 --> 00:04:54,500
So we can try to initialize both Latin LNG will do Fakher address, not lattitude.

70
00:04:56,290 --> 00:05:02,230
I'll get a comma at the end of that line and then fakher dot address, dot longitude like so.

71
00:05:03,290 --> 00:05:05,920
Even then, I still see an error message if we mouseover this.

72
00:05:06,080 --> 00:05:07,460
You'll notice that it says.

73
00:05:08,690 --> 00:05:12,650
Expected right here, type string is not assignable to type No.

74
00:05:12,880 --> 00:05:16,580
So remember when we were looking at the documentation for the latitude and longitude or the type definition

75
00:05:16,580 --> 00:05:20,990
filed just a second ago, we saw the latitude and longitude where functions that returned strings,

76
00:05:21,530 --> 00:05:24,500
but we clearly said that latitude and longitude were going to be numbers.

77
00:05:25,820 --> 00:05:30,110
Once again, in my opinion, this is kind of an oversight by the Fakher people and they really should

78
00:05:30,110 --> 00:05:31,260
be returning numbers here.

79
00:05:31,550 --> 00:05:33,820
However, that's just how they built this library.

80
00:05:33,830 --> 00:05:39,080
So we need to take the strings that are returned by latitude and longitude and convert them into numbers.

81
00:05:39,920 --> 00:05:44,690
To do so, we have to do an actual conversion process like this is a string right here.

82
00:05:44,690 --> 00:05:47,390
So we have to convert that into an actual number.

83
00:05:48,110 --> 00:05:51,140
So to do so, we're going to take a very JavaScript style approach.

84
00:05:51,530 --> 00:05:56,750
We're going to use the pass float function just to make sure you are aware the passport function is

85
00:05:56,750 --> 00:05:57,970
built into JavaScript.

86
00:05:58,190 --> 00:06:02,480
It takes a string and returns a number that has a decimal value attached to it.

87
00:06:03,260 --> 00:06:04,910
So we can call parts float on both.

88
00:06:06,260 --> 00:06:10,850
And the air goes away because now we are signing a no to both latitude and longitude.

89
00:06:12,010 --> 00:06:13,150
All right, so that's pretty much it.

90
00:06:13,880 --> 00:06:15,190
Let's take a quick pause right here.

91
00:06:15,220 --> 00:06:18,550
When we come back, the next video we're going to start to actually make use of our class.

92
00:06:18,550 --> 00:06:19,930
So we'll see you in just a minute.

