Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6208

ApolloClient Typescript Higher Order Component issue (not assignable to type)

$
0
0

I'm trying to create a HOC in a React Native app, but I'm having issues getting the definitions to work.

interface IWithApolloClientComponentProps {
    apolloClient: ApolloClient<any>;
}
export function withApolloClient<
    P extends IWithApolloClientComponentProps, 
    R = Omit<P, keyof IWithApolloClientComponentProps>
>(
    Component: React.ComponentType<P>
): React.ComponentType<R> {
        return function BoundComponent(props: R) {
            return <ApolloConsumer>{client => <Component {...props} apolloClient={client} />} . 
        </ApolloConsumer>;
    };
}

My VSCode keeps giving the following error:

Type 'R & { apolloClient: ApolloClient<object>; }' is not assignable to type 'IntrinsicAttributes & P & { children?: ReactNode; }'.
  Type 'R & { apolloClient: ApolloClient<object>; }' is not assignable to type 'P'.
'R & { apolloClient: ApolloClient<object>; }' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'IWithApolloClientComponentProps'.ts(2322)

Is anyone seeing something I'm doing terribly wrong here?


Viewing all articles
Browse latest Browse all 6208

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>