All this code around our action crater is definitely good, and it would definitely work right now,
but there's a shortcoming or two that I just want to point out very quickly.
I'm going to go down to where we dispatched the action of type search repositories success right here
to remember.
We had previously said that whenever we dispatch an action that looks like this, it would have a payload
property that is an array of strings.
But right now, I can very easily replace names right there with, say, a number.
And I do not get any kind of air coming from TypeScript.
If we tried to dispatch an action that looks like this, we would definitely end up with some kind of
error when we tried to run our code.
I can also put in a payload of a string or even null or undefined in all cases.
I get no errors whatsoever.
So I think that it would be really nice if we could somehow get TypeScript to understand how we are
calling dispatch right here and do some kind of checking and making sure that we are providing an appropriate
kind of action.
So to do so, we're going to provide a better type annotation for the dispatch function.
For that at the very top, I will import dispatch from Redux.
So this is a type definition for the dispatch function.
We can then replace any with dispatch.
Angle brackets and inside there, I'm going to write out action.
Remember, action is a type that you and I put together inside of our actions in Dexter's final years
actions index notes, we had exported action and that type was essentially all the different kinds of
valid actions that exist inside of our project.
So this code right here of dispatch angle brackets action is pretty much telling TypeScript, that we
are going to get a function right here that can only be called with some argument that matches this
type of action.
So now if we go back down and try replacing payload right here with some array of strings, we're going
to very quickly get an air.
Says that we are providing a string, but if we want to call dispatch with this type specifically,
then we must provide a payload that is an array of strings.
Likewise, if we go down to where we dispatch this type of air down here, remember, we can only dispatch
this type of air with an object or see an action that has a payload that is a string to if try replacing
air message there with a number, I'll get an air as well that says a payload needs to be a string in
this case.
But you provided a number.
So that's how we can very easily get TypeScript to better understand this dispatch argument and make
sure that we are dispatching the correct kind of action inside of all of our different action.
Creator's.
OK, so that is a good improvement as well.
Well, I think the last major thing we need to do is set up our redock store itself and then we can
start to work on the actual side of our application.