Now speaking of callbacks and function types there it works pretty much in the same way.
Let's say we have a new function up there AD and handle.
Let's say there we expect to get two numbers and then I also want to get a callback function here.
So a function which is passed in is an argument that should do something with the result.
Then here we could generate the result of course but now I'm not returning it.
But instead I want to call the callback function and pass in result.
Now for that I want to be really clear that callback should be a function.
So again I'm using that function type definition that maybe does not return anything but that does take
a number as an argument because we're passing it a number here so the callback function the function
we're passing into this function as a parameter should accept a number.
And now down there we could call add and handle pass in 10 and 20 and then passing a function for example
an anonymous function here.
So now here when we call the function this is of course not a function type but a concrete value we're
passing in for this third argument.
So this now here is an anonymous function creating here and there we know we'll get a number maybe name
it or assault here and then we can do with it whatever we want.
Now if you compiled is we see this locked down there 30 which is the result of our callback function
which we pass to add and handle where add and handle combines the two numbers and then calls the callback
where to call that has to meet this condition here.
The advantage of us to finding the callback function definition here is dead inside of the function
we pass in as a callback typescript is able to infer that result will be a number and hence we could
do anything with result here.
What we could do with a number without explicitly stating the type here because typescript nodes result
will be a number because we made it really clear that the callback will get one argument which is a
number hence all the if we would expect the second arguments here into callback we'd get an error because
we know well the callback we expect in our ad and handle function only should have one argument.
So if we then pass on a callback function which takes a second argument that clearly is a mistake.
The only thing typescript does not pick up is if we return something here.
If a return result then the callback does return something even though we made it clear that it shouldn't
return anything.
This however is not a mistake or a bag and typescript it actually happens on purpose by specifying void
here on our callback type.
We're essentially saying we'll ignore any result you might be returning here.
So we're basically saying in AD and handle where we get that callback function will not do anything
with the return type.
That's why you will be able to return something here without punishment.
But you know because it's clearly defined here on the callback type that the callback will not do anything
with the value you might return here.
So that ad and handle inside of the function will not do anything with that value.
You might be returning and that's of course a useful piece of information you might expect it in here.
We're doing something with the value returned by the callback and by specifying this type here we make
it really clear that instead of ad and handler we're not interested in any return value.
So this does not force you to pass in a callback that doesn't return anything.
It just tells you that anything you might return will not be used for the parameters it's of course
different.
There does isn't forest because here it really matters that you know if you're passing a callback that
expects more parameters well then you'll get an error or you'll not get the result you want because
I only give you one result.
So dear we can't just ignore what you might want as it's the case for the return type.
We can ignore that here for passing something in we're the ad and handle function is responsible for
that because that's where to call that gets called.
This is why parameters are enforced and then typescript is really strict regarding the number and type
of parameters of callback functions and why doesn't really care about the return type.