There's one last quick thing I want mentioned around functions so down here at the very bottom we're
going to add in one last example here.
Let's imagine for a second we have some object that describes today's weather.
So maybe we call it forecast like so and maybe it's got a date to indicate today's date and the current
weather outside.
So maybe that will be a string that we'll call Sunny like so.
Now let's try creating a function that's going to take that forecast and just log out the weather so
to do so we could say something like const log weather and we're going to get some forecast object.
We need to annotate the return type or singing the argument type right here.
So to do so we would put in an object literal just like we saw previously with our variable annotation
like what we saw right here so we would put in a call in and then curly braces and list out all the
different properties that we would expect this forecast object to have.
So maybe it will be a date that has a date type and a weather that has a string type thing in zoom out
for just a second so you can see that whole line then after the list right there I'm only going to try
to log out the current weather so there's not going to be anything I'm going to return.
So Mark the return type is void and then put down my arrow where the function like so
you're going to zoom back in.
So now if we wanted to we could do a quick console log of forecast dot date and a console log of say
forecast not weather like so and then just as a quick example down here we could try calling log weather
with a forecast object and just to make the variables in here a little bit more clear maybe rather than
calling this forecast it should be like today's weather.
Maybe that makes a lot more sense.
Now it's better all right now one little optimization we could do here would be to use a little bit
of yes 2015 syntax and attempt to D structure the dates in weather properties out of the forecast variable
right there.
So in other words rather than having to refer to forecast start date and forecast out whether I want
to just pull those two properties directly off inside the argument list if we were using normal.
Yes 2015 syntax I'll put a quick example right here.
We would write out something like this.
We would say const log whether And then inside the argument list we would put a set of curly braces.
And list the two properties we wanted to access.
So in this case date and weather like so and then we could do a simple console log of date and of weather.
So how do we use this kind of syntax right here.
With a typescript annotation.
All right I'm going to remove the yes 2015 and we're going to adjust the syntax in here just a little
bit.
So if we ever want to use these structuring along with an annotation all we have to do is replace the
variable itself with the actual D structuring statement.
So instead of forecast right there I'm going to replace it with a set of curly braces and I'll list
out the different properties I want to pull out of that object.
So the date and weather like cell and then I can adjust the body the function to be just state and whether
so noticed that we did not tried to stick the annotation types along with the D structuring the D structuring
portion and the annotation are always going to be two separate statements separated by that colon right
there.
So we're first going to do our D structuring and then we'll try to do with the actual annotation right
after it.
All right.
So now we've seen that another quick pause right here and we'll move on to our last subject around annotations
and inference.