这是我的调度道具定义:
type DispatchProps = {
selectRow: (index: number) => void,
loadData: (fetchArgs: FetchArgs) => void,
};
// This works
const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({
selectRow: (selectedRowIndex: number) => dispatch(actions.selectRow(selectedRowIndex)),
loadData: (fetchArgs: FetchArgs) => dispatch(actions.loadData(fetchArgs)),
});
// This doesn't work
const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => bindActionCreators({
selectRow: actions.selectRow,
loadData: actions.loadData,
}, dispatch);
Flow抱怨说:
SelectRowAction [1] is incompatible with undefined [2] in the return value of property `selectRow`.
如果bindActionCreator
类型定义试图返回动作创建者返回值(在本例中为SelectRowAction
),但这并没有任何意义,因为那些值传递给dispatch
,调度应该返回undefined
。
我错过了什么?
答案 0 :(得分:0)
我遇到了同样的问题,您需要在DispatchProps中定义函数的返回类型,而不是void
例如:
type DispatchProps = {
selectRow: (index: number) => SelectRowActionType,
loadData: (fetchArgs: FetchArgs) => LoadDataActionType,
};