1
00:00:01,030 --> 00:00:05,950
The next thing I would like to do is to apply a better type invitation to this action argument.

2
00:00:06,220 --> 00:00:11,290
Remember, in general, whenever we have a type of any as an annotation inside a typescript, that's

3
00:00:11,290 --> 00:00:16,059
usually a bad sign because it means that typescript isn't going to really try to figure out what this

4
00:00:16,059 --> 00:00:18,700
action thing is or what different properties it has.

5
00:00:19,390 --> 00:00:25,120
So let's try defining or better annotating better describing what this action argument really is to

6
00:00:25,120 --> 00:00:25,240
do.

7
00:00:25,240 --> 00:00:29,320
So I'm going to make an interface above my reducer called action.

8
00:00:30,290 --> 00:00:36,140
Remember that entire script, every action is always going to be an object that must have a type property

9
00:00:36,500 --> 00:00:38,750
and optionally it can also have a payload.

10
00:00:39,140 --> 00:00:41,630
So I'm going to reflect that inside of our interface right here.

11
00:00:41,660 --> 00:00:48,230
I'm going to say that in action is something that must have a type that is a string and optionally can

12
00:00:48,230 --> 00:00:48,920
have a payload.

13
00:00:50,290 --> 00:00:54,940
So the question mark right here says that it may or may not have a paler property, and if it does have

14
00:00:54,940 --> 00:00:56,530
one, it can be of any type.

15
00:00:57,860 --> 00:01:02,390
Now, I'm going to say that this action argument is of type action like so.

16
00:01:04,500 --> 00:01:10,020
That's definitely a reasonable improvement now TypeScript is aware that this action will have a type.

17
00:01:10,620 --> 00:01:15,090
So if we ever write out right here inside of our switch statement, something like Action Dot, t.P,

18
00:01:15,090 --> 00:01:21,770
Wii, it will jump in and say, hey, you don't actually have a Wii property, but you do have a type

19
00:01:21,780 --> 00:01:22,200
property.

20
00:01:22,860 --> 00:01:27,660
In addition, if we ever try to access Actionist payload and we accidentally typed out something like

21
00:01:28,140 --> 00:01:34,220
why load like so once again we would get an error and we would be told there is no payload property.

22
00:01:34,230 --> 00:01:36,110
Instead it is payload like so.

23
00:01:37,330 --> 00:01:43,060
Well, that's definitely a reasonable improvement, but now once again, we have a type of any and like

24
00:01:43,060 --> 00:01:46,540
I just mentioned, wherever possible, we want to avoid having types of any.

25
00:01:47,260 --> 00:01:51,770
So although this is an improvement, we still can fix this up a little bit more.

26
00:01:52,060 --> 00:01:54,610
Let's take a look at some further improvements in just a moment.

