我使用重组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>;
}