1
- function bindActionCreator ( actionCreator , dispatch ) {
2
- return function ( ) {
3
- return dispatch ( actionCreator . apply ( this , arguments ) )
1
+ import { AnyAction , ActionCreator , Dispatch , ActionCreatorsMapObject } from '..'
2
+
3
+ function bindActionCreator < A extends AnyAction = AnyAction > (
4
+ actionCreator : ActionCreator < A > ,
5
+ dispatch : Dispatch
6
+ ) {
7
+ return function ( this : any , ...args : any [ ] ) {
8
+ return dispatch ( actionCreator . apply ( this , args ) )
4
9
}
5
10
}
6
11
@@ -13,19 +18,22 @@ function bindActionCreator(actionCreator, dispatch) {
13
18
* For convenience, you can also pass an action creator as the first argument,
14
19
* and get a dispatch wrapped function in return.
15
20
*
16
- * @param { Function|Object } actionCreators An object whose values are action
21
+ * @param actionCreators An object whose values are action
17
22
* creator functions. One handy way to obtain it is to use ES6 `import * as`
18
23
* syntax. You may also pass a single function.
19
24
*
20
- * @param { Function } dispatch The `dispatch` function available on your Redux
25
+ * @param dispatch The `dispatch` function available on your Redux
21
26
* store.
22
27
*
23
- * @returns { Function|Object } The object mimicking the original object, but with
28
+ * @returns The object mimicking the original object, but with
24
29
* every action creator wrapped into the `dispatch` call. If you passed a
25
30
* function as `actionCreators`, the return value will also be a single
26
31
* function.
27
32
*/
28
- export default function bindActionCreators ( actionCreators , dispatch ) {
33
+ export default function bindActionCreators (
34
+ actionCreators : ActionCreator < any > | ActionCreatorsMapObject ,
35
+ dispatch : Dispatch
36
+ ) {
29
37
if ( typeof actionCreators === 'function' ) {
30
38
return bindActionCreator ( actionCreators , dispatch )
31
39
}
@@ -39,7 +47,7 @@ export default function bindActionCreators(actionCreators, dispatch) {
39
47
)
40
48
}
41
49
42
- const boundActionCreators = { }
50
+ const boundActionCreators : ActionCreatorsMapObject = { }
43
51
for ( const key in actionCreators ) {
44
52
const actionCreator = actionCreators [ key ]
45
53
if ( typeof actionCreator === 'function' ) {
0 commit comments