1 00:00:01,000 --> 00:00:04,690 There's one last quick thing I want mentioned around functions so down here at the very bottom we're 2 00:00:04,690 --> 00:00:07,210 going to add in one last example here. 3 00:00:07,330 --> 00:00:11,050 Let's imagine for a second we have some object that describes today's weather. 4 00:00:11,050 --> 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,020 --> 00:00:18,020 weather outside. 6 00:00:18,100 --> 00:00:21,990 So maybe that will be a string that we'll call Sunny like so. 7 00:00:22,110 --> 00:00:27,040 Now let's try creating a function that's going to take that forecast and just log out the weather so 8 00:00:27,040 --> 00:00:34,900 to do so we could say something like const log weather and we're going to get some forecast object. 9 00:00:35,090 --> 00:00:38,540 We need to annotate the return type or singing the argument type right here. 10 00:00:38,570 --> 00:00:44,210 So to do so we would put in an object literal just like we saw previously with our variable annotation 11 00:00:44,480 --> 00:00:51,140 like what we saw right here so we would put in a call in and then curly braces and list out all the 12 00:00:51,140 --> 00:00:54,610 different properties that we would expect this forecast object to have. 13 00:00:54,680 --> 00:01:01,370 So maybe it will be a date that has a date type and a weather that has a string type thing in zoom out 14 00:01:01,370 --> 00:01:07,310 for just a second so you can see that whole line then after the list right there I'm only going to try 15 00:01:07,310 --> 00:01:11,120 to log out the current weather so there's not going to be anything I'm going to return. 16 00:01:11,120 --> 00:01:15,740 So Mark the return type is void and then put down my arrow where the function like so 17 00:01:18,760 --> 00:01:20,450 you're going to zoom back in. 18 00:01:20,460 --> 00:01:27,870 So now if we wanted to we could do a quick console log of forecast dot date and a console log of say 19 00:01:28,020 --> 00:01:36,250 forecast not weather like so and then just as a quick example down here we could try calling log weather 20 00:01:36,880 --> 00:01:41,530 with a forecast object and just to make the variables in here a little bit more clear maybe rather than 21 00:01:41,530 --> 00:01:44,380 calling this forecast it should be like today's weather. 22 00:01:44,410 --> 00:01:46,190 Maybe that makes a lot more sense. 23 00:01:47,840 --> 00:01:53,300 Now it's better all right now one little optimization we could do here would be to use a little bit 24 00:01:53,300 --> 00:02:00,410 of yes 2015 syntax and attempt to D structure the dates in weather properties out of the forecast variable 25 00:02:00,410 --> 00:02:01,710 right there. 26 00:02:01,730 --> 00:02:06,320 So in other words rather than having to refer to forecast start date and forecast out whether I want 27 00:02:06,320 --> 00:02:11,900 to just pull those two properties directly off inside the argument list if we were using normal. 28 00:02:11,930 --> 00:02:14,870 Yes 2015 syntax I'll put a quick example right here. 29 00:02:14,870 --> 00:02:16,100 We would write out something like this. 30 00:02:16,100 --> 00:02:23,370 We would say const log whether And then inside the argument list we would put a set of curly braces. 31 00:02:23,380 --> 00:02:25,840 And list the two properties we wanted to access. 32 00:02:25,930 --> 00:02:35,070 So in this case date and weather like so and then we could do a simple console log of date and of weather. 33 00:02:35,210 --> 00:02:37,520 So how do we use this kind of syntax right here. 34 00:02:38,220 --> 00:02:40,700 With a typescript annotation. 35 00:02:40,740 --> 00:02:44,790 All right I'm going to remove the yes 2015 and we're going to adjust the syntax in here just a little 36 00:02:44,790 --> 00:02:45,770 bit. 37 00:02:45,840 --> 00:02:50,580 So if we ever want to use these structuring along with an annotation all we have to do is replace the 38 00:02:50,580 --> 00:02:53,700 variable itself with the actual D structuring statement. 39 00:02:54,010 --> 00:02:59,160 So instead of forecast right there I'm going to replace it with a set of curly braces and I'll list 40 00:02:59,160 --> 00:03:02,450 out the different properties I want to pull out of that object. 41 00:03:02,550 --> 00:03:08,400 So the date and weather like cell and then I can adjust the body the function to be just state and whether 42 00:03:09,380 --> 00:03:16,180 so noticed that we did not tried to stick the annotation types along with the D structuring the D structuring 43 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 44 00:03:21,670 --> 00:03:22,400 there. 45 00:03:22,400 --> 00:03:26,950 So we're first going to do our D structuring and then we'll try to do with the actual annotation right 46 00:03:26,950 --> 00:03:28,720 after it. 47 00:03:28,920 --> 00:03:29,190 All right. 48 00:03:29,190 --> 00:03:33,870 So now we've seen that another quick pause right here and we'll move on to our last subject around annotations 49 00:03:33,930 --> 00:03:34,890 and inference.