1
00:00:00,920 --> 00:00:04,580
There's one last quick thing I want to mention around functions, so down here at the very bottom,

2
00:00:04,580 --> 00:00:06,700
we're going to add in one last example here.

3
00:00:07,250 --> 00:00:10,700
Let's imagine for a second, do we have some object that describes today's weather?

4
00:00:10,970 --> 00:00:17,020
So maybe we call it forecast like so and maybe it's got a date to indicate today's date and the current

5
00:00:17,030 --> 00:00:17,930
weather outside.

6
00:00:18,000 --> 00:00:20,720
So maybe that will be a string that we'll call Sunny like so.

7
00:00:22,020 --> 00:00:26,310
Now, let's try creating a function that's going to take that forecast and just log out the weather,

8
00:00:26,850 --> 00:00:33,210
so to do so, we could say something like const log weather and then we're going to get some forecast

9
00:00:33,210 --> 00:00:33,870
object.

10
00:00:35,000 --> 00:00:39,950
We need to annotate the return type of the argument type right here, so to do so, we would put in

11
00:00:39,950 --> 00:00:45,440
an object literal, just like we saw previously with our variable annotation, like what we saw right

12
00:00:45,440 --> 00:00:45,740
here.

13
00:00:47,070 --> 00:00:52,200
So we would put in a colon and then curly braces and list out all the different properties that we would

14
00:00:52,200 --> 00:00:54,000
expect this forecast object to have.

15
00:00:54,660 --> 00:01:00,330
So maybe it will be a date that has a date type and a weather that has a string type.

16
00:01:00,920 --> 00:01:03,150
And zoom out for just a second so you can see that whole line.

17
00:01:04,459 --> 00:01:09,140
Then after the list right there, I'm only going to try to log out the current weather so there's not

18
00:01:09,140 --> 00:01:13,910
going to be anything I'm going to return, so I'll mark the return type is void and then put down my

19
00:01:13,910 --> 00:01:15,770
arrow for the function like so.

20
00:01:18,820 --> 00:01:19,720
I'm going to zoom back in.

21
00:01:20,430 --> 00:01:27,340
So now if we wanted to, we could do a quick control log of forecast dot date and a console log of,

22
00:01:27,340 --> 00:01:30,580
say, forecast, not weather like so.

23
00:01:32,690 --> 00:01:38,150
And then just as a quick example down here, we could try calling log weather with the forecast object

24
00:01:38,810 --> 00:01:42,470
and just to make the variables in here a little bit more clear, maybe rather than calling this forecast,

25
00:01:42,470 --> 00:01:44,330
it should be like today's weather.

26
00:01:44,360 --> 00:01:45,790
Maybe that makes a little bit more sense.

27
00:01:49,880 --> 00:01:55,100
All right, now, one little optimization we could do here would be to use a little bit of 2015 syntax

28
00:01:55,250 --> 00:02:00,860
and attempt to restructure the dates and whether properties out of the forecast variable right there.

29
00:02:01,670 --> 00:02:06,380
So in other words, rather than having to refer to forecast update and forecast out whether I want to

30
00:02:06,380 --> 00:02:12,800
just pull those two properties directly off inside the argument list, if we were using normal E 2015

31
00:02:12,800 --> 00:02:14,660
syntax, I'll put a quick example right here.

32
00:02:14,810 --> 00:02:16,070
We would write out something like this.

33
00:02:16,070 --> 00:02:17,840
We would say const log whether.

34
00:02:20,210 --> 00:02:24,830
And then inside the argument list, we would put a set of curly braces and list the two properties we

35
00:02:24,830 --> 00:02:25,850
wanted to access.

36
00:02:25,880 --> 00:02:29,060
So in this case, date and weather like so.

37
00:02:29,510 --> 00:02:31,940
And then we could do a simple console log of date.

38
00:02:33,120 --> 00:02:37,260
And of weather, so how do we use this kind of syntax right here?

39
00:02:38,170 --> 00:02:39,800
With a typescript invitation.

40
00:02:40,600 --> 00:02:44,800
All right, I'm going to remove the 2015 and we're going to adjust the syntax in here just a little

41
00:02:44,800 --> 00:02:45,090
bit.

42
00:02:45,790 --> 00:02:50,440
So if we ever want to use these structuring along with an annotation, all we have to do is replace

43
00:02:50,440 --> 00:02:53,350
the variable itself with the actual structuring statement.

44
00:02:53,990 --> 00:02:59,170
So instead of forecast right there, I'm going to replace it with a set of curly braces and I'll list

45
00:02:59,170 --> 00:03:02,080
out the different properties I want to pull out of that object.

46
00:03:02,500 --> 00:03:03,130
So be a date.

47
00:03:03,130 --> 00:03:08,440
And whether like so and then I can adjust the body, the function to be just date and whether.

48
00:03:09,520 --> 00:03:16,180
So notice that we did not try to stick the annotation types along with the structuring, the D structuring

49
00:03:16,180 --> 00:03:21,670
portion and the annotation are always going to be two separate statements separated by that colon right

50
00:03:21,670 --> 00:03:21,940
there.

51
00:03:22,390 --> 00:03:27,220
So we're first going to do our restructuring and then we'll try to do the actual annotation right after

52
00:03:27,220 --> 00:03:27,430
it.

53
00:03:28,780 --> 00:03:32,770
All right, so now we've seen that another quick pause right here and we'll move on to our last subject

54
00:03:32,770 --> 00:03:34,870
around annotations and inference.

