为事件中的动作提供流注释的类型

时间:2019-01-10 18:34:06

标签: javascript react-redux flowtype

我创建用于注册和登录的简单表格,我也有发送请求的服务器。 我有组件LogoutButton

const Logout = (props: Props): Node => {
  function proceedLogout(logout: Action) {
    const userDataJSON: ?string = localStorage.getItem('userData');
    if (userDataJSON) {
      const {sessionID, userID,}: {sessionID: string, userID: string} = JSON.parse(userDataJSON);
      logout({sessionID, userID,});
    }
  }

  const {isLoading, logout,} = props;
  function LogoutButton({isLoading, logout,}: Props): Node {
    if (isLoading) {
      return (<div>Loading...</div>);
    }
    return (
      <Button onClick={(): void => proceedLogout(logout)}>Logout</Button>
    );
  }
  return LogoutButton({isLoading, logout,});
};

导入类型:

export type Action = {
  type: string,
  payload?: Error
};
type Props = {
  isLoading: boolean,
  logout: ({sessionID: string, userID: string}) => void
};

并遇到此流程问题

Cannot call `logout` because a callable signature is missing in `Action` [1]. (LogoutButton.js:58:7)
Cannot call `proceedLogout` with `logout` bound to `logout` because property `type` is missing in function type [1] but exists in `Action` [2]. (LogoutButton.js:68:50)

我需要为注销或操作,为procedLogout或输出procedLogout添加什么类型?

0 个答案:

没有答案