These are complete declarations for ActionCreator and bindActionCreators:
declare type ActionCreator<A, B> = (...args: Array<B>) => A; declare type ActionCreators<K, A> = { [key: K]: ActionCreator<A, any> }; declare function bindActionCreators<A, C: ActionCreator<A, any>>(actionCreator: C, dispatch: Dispatch<A>): C; declare function bindActionCreators<A, K, C: ActionCreators<K, A>>(actionCreators: C, dispatch: Dispatch<A>): C;
In your code, bindActionCreators will wrap each profileActionCreators property in dispatch . It seems you expect the send to be passed to the setProfile function, where the send can later be used as a callback.
But it doesn’t seem to me that bindActionCreators supports “bind” sending as a callback. Rather, the submission is “linked” as follows:
function bindActionCreator(actionCreator, dispatch) { return (...args) => dispatch(actionCreator(...args)) }
So, in your code, it looks something like this:
function mapDispatchToProps(dispatch: Dispatch<Action>): Props { return { actions: { setProfile: (profile) => dispatch(dispatch => setTimeout(() => dispatch({ type: 'SET_PROFILE', profile }), 2000)), }; }
Thus, Flowtype correctly detects a type error, stating that bindActionCreators expects each property of the object to be actionCreator: () => Action .
You probably can't use bindActionCreators for your use case, or you need to rethink how you deal with thunks. Here is an approach that should work .
const profileActionCreators = { setProfile }; type Props = { actions: { setProfile: (profile: Profile) => setTimeout, } } function mapDispatchToProps(dispatch: Dispatch<Action>): Props { const boundActions = bindActionCreators( profileActionCreators, dispatch ); return ({ actions: { setProfile: (profile: Profile) => setTimeout(() => boundActions.setProfile(profile), 2000), }, }); }
Thunk Approach
If you want to maintain the ThunkAction approach, you cannot use bindActionCreators. This also works.