如何使用打字稿,react-adopt和react-apollo组件?

时间:2019-06-27 22:08:06

标签: reactjs typescript react-apollo

我正在尝试正确键入react-adopt组件,因为我具有以下接口:

interface LoginData {
  token: string;
}

interface LoginVars {
  email: string;
  password: string;
}

interface UserData {
  name: string;
  age: number;
}

interface UserVars {
  id: string;
}

这是我的Composed组件,请注意,唯一类型正确的东西是react-apollo组件,但是我不知道如何键入react-adopt的adopt函数:

const Composed = adopt({
  login: ({ render, variables }) => (
    <Mutation<LoginData, LoginVars>
      mutation={MUTATION_LOGIN}
      variables={variables}
    >
      {(mutation, result) => render({ mutation, result })}
    </Mutation>
  ),
  user: ({ render, variables }) => (
    <Query<UserData, UserVars> query={MUTATION_USER} variables={variables}>
      {render}
    </Query>
  )
});

最后我有了一个根本没有类型的实现:

const Foo = () => {
  return (
    <Composed>
      {({ login, user }) => {
        // Both `login` and `user` are `any` type
      }}
    </Composed>
  )
}

有人知道如何正确键入adopt函数吗?。

0 个答案:

没有答案
相关问题