1
00:00:00,660 --> 00:00:04,200
All this code around our action crater is definitely good, and it would definitely work right now,

2
00:00:04,200 --> 00:00:07,080
but there's a shortcoming or two that I just want to point out very quickly.

3
00:00:07,590 --> 00:00:13,080
I'm going to go down to where we dispatched the action of type search repositories success right here

4
00:00:13,530 --> 00:00:14,010
to remember.

5
00:00:14,010 --> 00:00:18,210
We had previously said that whenever we dispatch an action that looks like this, it would have a payload

6
00:00:18,210 --> 00:00:19,860
property that is an array of strings.

7
00:00:20,470 --> 00:00:24,630
But right now, I can very easily replace names right there with, say, a number.

8
00:00:25,200 --> 00:00:28,110
And I do not get any kind of air coming from TypeScript.

9
00:00:28,470 --> 00:00:32,280
If we tried to dispatch an action that looks like this, we would definitely end up with some kind of

10
00:00:32,280 --> 00:00:33,810
error when we tried to run our code.

11
00:00:34,400 --> 00:00:40,740
I can also put in a payload of a string or even null or undefined in all cases.

12
00:00:40,740 --> 00:00:42,270
I get no errors whatsoever.

13
00:00:43,110 --> 00:00:47,940
So I think that it would be really nice if we could somehow get TypeScript to understand how we are

14
00:00:47,940 --> 00:00:52,950
calling dispatch right here and do some kind of checking and making sure that we are providing an appropriate

15
00:00:52,950 --> 00:00:53,940
kind of action.

16
00:00:54,690 --> 00:00:59,580
So to do so, we're going to provide a better type annotation for the dispatch function.

17
00:01:00,270 --> 00:01:05,250
For that at the very top, I will import dispatch from Redux.

18
00:01:05,850 --> 00:01:08,780
So this is a type definition for the dispatch function.

19
00:01:09,480 --> 00:01:12,150
We can then replace any with dispatch.

20
00:01:13,220 --> 00:01:16,310
Angle brackets and inside there, I'm going to write out action.

21
00:01:17,670 --> 00:01:23,470
Remember, action is a type that you and I put together inside of our actions in Dexter's final years

22
00:01:23,510 --> 00:01:30,590
actions index notes, we had exported action and that type was essentially all the different kinds of

23
00:01:30,590 --> 00:01:32,930
valid actions that exist inside of our project.

24
00:01:33,980 --> 00:01:40,610
So this code right here of dispatch angle brackets action is pretty much telling TypeScript, that we

25
00:01:40,610 --> 00:01:46,760
are going to get a function right here that can only be called with some argument that matches this

26
00:01:46,760 --> 00:01:47,480
type of action.

27
00:01:49,520 --> 00:01:55,280
So now if we go back down and try replacing payload right here with some array of strings, we're going

28
00:01:55,280 --> 00:01:56,360
to very quickly get an air.

29
00:01:57,260 --> 00:02:02,630
Says that we are providing a string, but if we want to call dispatch with this type specifically,

30
00:02:02,840 --> 00:02:05,210
then we must provide a payload that is an array of strings.

31
00:02:06,210 --> 00:02:12,840
Likewise, if we go down to where we dispatch this type of air down here, remember, we can only dispatch

32
00:02:12,840 --> 00:02:18,180
this type of air with an object or see an action that has a payload that is a string to if try replacing

33
00:02:18,180 --> 00:02:23,160
air message there with a number, I'll get an air as well that says a payload needs to be a string in

34
00:02:23,160 --> 00:02:23,550
this case.

35
00:02:23,550 --> 00:02:24,810
But you provided a number.

36
00:02:25,900 --> 00:02:30,400
So that's how we can very easily get TypeScript to better understand this dispatch argument and make

37
00:02:30,400 --> 00:02:34,510
sure that we are dispatching the correct kind of action inside of all of our different action.

38
00:02:34,510 --> 00:02:35,080
Creator's.

39
00:02:35,980 --> 00:02:38,050
OK, so that is a good improvement as well.

40
00:02:38,700 --> 00:02:42,670
Well, I think the last major thing we need to do is set up our redock store itself and then we can

41
00:02:42,670 --> 00:02:45,430
start to work on the actual side of our application.

