There's one last quick thing I want to mention 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, do 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 then we're going to get some forecast
object.
We need to annotate the return type of 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 colon 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.
And 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 I'll mark the return type is void and then put down my
arrow for the function like so.
I'm going to zoom back in.
So now if we wanted to, we could do a quick control 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 the 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 little bit more sense.
All right, now, one little optimization we could do here would be to use a little bit of 2015 syntax
and attempt to restructure the dates and whether properties out of the forecast variable right there.
So in other words, rather than having to refer to forecast update and forecast out whether I want to
just pull those two properties directly off inside the argument list, if we were using normal E 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 invitation.
All right, I'm going to remove the 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 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 be a date.
And whether like so and then I can adjust the body, the function to be just date and whether.
So notice that we did not try to stick the annotation types along with the 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 restructuring and then we'll try to do 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.