The next thing I would like to do is to apply a better type invitation to this action argument.
Remember, in general, whenever we have a type of any as an annotation inside a typescript, that's
usually a bad sign because it means that typescript isn't going to really try to figure out what this
action thing is or what different properties it has.
So let's try defining or better annotating better describing what this action argument really is to
do.
So I'm going to make an interface above my reducer called action.
Remember that entire script, every action is always going to be an object that must have a type property
and optionally it can also have a payload.
So I'm going to reflect that inside of our interface right here.
I'm going to say that in action is something that must have a type that is a string and optionally can
have a payload.
So the question mark right here says that it may or may not have a paler property, and if it does have
one, it can be of any type.
Now, I'm going to say that this action argument is of type action like so.
That's definitely a reasonable improvement now TypeScript is aware that this action will have a type.
So if we ever write out right here inside of our switch statement, something like Action Dot, t.P,
Wii, it will jump in and say, hey, you don't actually have a Wii property, but you do have a type
property.
In addition, if we ever try to access Actionist payload and we accidentally typed out something like
why load like so once again we would get an error and we would be told there is no payload property.
Instead it is payload like so.
Well, that's definitely a reasonable improvement, but now once again, we have a type of any and like
I just mentioned, wherever possible, we want to avoid having types of any.
So although this is an improvement, we still can fix this up a little bit more.
Let's take a look at some further improvements in just a moment.