1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
import {
ActionCreator,
Action,
Dispatch,
bindActionCreators,
ActionCreatorsMapObject,
} from 'redux'
interface AddTodoAction extends Action {
text: string
}
const addTodo: ActionCreator<AddTodoAction> = (text: string) => ({
type: 'ADD_TODO',
text,
})
const addTodoAction: AddTodoAction = addTodo('test')
type AddTodoThunk = (dispatch: Dispatch) => AddTodoAction
const addTodoViaThunk: ActionCreator<AddTodoThunk> = (text: string) => (
dispatch: Dispatch
) => ({
type: 'ADD_TODO',
text,
})
declare const dispatch: Dispatch
const boundAddTodo = bindActionCreators(addTodo, dispatch)
const dispatchedAddTodoAction: AddTodoAction = boundAddTodo('test')
const boundAddTodoViaThunk = bindActionCreators<
ActionCreator<AddTodoThunk>,
ActionCreator<AddTodoAction>
>(addTodoViaThunk, dispatch)
const dispatchedAddTodoViaThunkAction: AddTodoAction = boundAddTodoViaThunk(
'test'
)
const boundActionCreators = bindActionCreators({ addTodo }, dispatch)
const otherDispatchedAddTodoAction: AddTodoAction = boundActionCreators.addTodo(
'test'
)
interface M extends ActionCreatorsMapObject {
addTodoViaThunk: ActionCreator<AddTodoThunk>
}
interface N extends ActionCreatorsMapObject {
addTodoViaThunk: ActionCreator<AddTodoAction>
}
const boundActionCreators2 = bindActionCreators<M, N>(
{
addTodoViaThunk,
},
dispatch
)
const otherDispatchedAddTodoAction2: AddTodoAction = boundActionCreators2.addTodoViaThunk(
'test'
)
|