首页 > 解决方案 > 在 react redux 项目中使用流

问题描述

在尝试将类型应用于连接功能时,我遇到了一些烦人的问题。我不确定,流程是否正确实施。我将相同的实现应用于 2 个单独的 JS 文件,一个还可以,但另一个不断引发这样的错误

1. all branches are incompatible: Either  null [1] is incompatible with  function type [2]. Or  null [1] is incompatible with  function type [3].Flow(InferError)

2. a call signature declaring the expected parameter / return type is missing in  `ReduxDispatchProps` [1] but exists in  function type [2] in the return value.Flow(InferError)

顺便说一句,这是我的实现。

interface ReactProps {
  user?: User;
  asset?: Asset;
  autoUpdate?: boolean;
  std_time?: number;
  handleOpenModalUpdateStandardTime?: (standardTime: StandardTime) => void;
}

interface ReduxStateProps {}

interface ReduxDispatchProps {
  updateEntityStandardTime: UpdateEntityStandardTimeHandler;
}

interface IProps extends ReduxStateProps, ReactProps, ReduxDispatchProps {}

class ComponentA extends Component<IProps,{}> {}

const mapDispatchToProps = (dispatch): ReduxDispatchProps => {
  return {
    updateEntityStandardTime: (payload: StandardTime, callback: ?Callback) =>
      dispatch(updateEntityStandardTimeRequest(payload, callback)),
  };
};

export default connect<IProps, ReactProps, _, _, _, _>(
  null,
  mapDispatchToProps
)(ComponentA);

期待你们的帮助!

标签: reactjsreduxflowtype

解决方案


推荐阅读