是否可以组合重组和反应阿波罗流量类型

时间:2018-08-09 07:17:15

标签: flowtype react-apollo recompose flow-typed

我使用重组compose函数来组合HOC。现在,我想使用流类型来键入它。因为我不仅使用compose的recompose函数,而且还使用其他库中的HOC,所以我想知道是否甚至可以键入以下内容:

export type Response = { user: User }
export type Props = { user: User}

const userQuery: OperationComponent<
    Response,
    {},
    {},
    Props
> = graphql(UserQuery, {
    props: ({ data: { user } }) => ({
        user,
    }),
})

const enhance: HOC<*, Props & {test: 'test'}> = compose(
  userQuery, 
  withProps()=> ({test: 'test'}
)

此刻我得到了:

[flow] Cannot assign `compose(...)` to `enhance` because property `user`
is missing in object type [1] but exists in `Props` [2] in type 
argument `Props` [3] of the return value. (References: [1] [2] [3])
react-apollo的

OperationComponent定义如下:

declare export interface OperationComponent<
    TResult: Object = {},
    TOwnProps: Object = {},
    TVariables: Object = {},
    TMergedProps: Object = ChildProps<TOwnProps, TResult, TVariables>
  > {
    (
      component: React$ComponentType<TMergedProps>
    ): React$ComponentType<TOwnProps>;
  }

0 个答案:

没有答案