Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

update type definition of withApollo #3538

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/components/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface QueryComponentOptions<
TData = any,
TVariables = OperationVariables
> extends QueryFunctionOptions<TData, TVariables> {
children: (result: QueryResult<TData, TVariables>) => JSX.Element | null;
children: (result: QueryResult<TData, TVariables>) => React.ReactNode
query: DocumentNode;
}

Expand All @@ -32,7 +32,7 @@ export interface MutationComponentOptions<
export interface SubscriptionComponentOptions<
TData = any,
TVariables = OperationVariables
> extends BaseSubscriptionOptions<TData, TVariables> {
> extends BaseSubscriptionOptions<TData, TVariables> {
subscription: DocumentNode;
children?: null | ((result: SubscriptionResult<TData>) => JSX.Element | null);
}
8 changes: 3 additions & 5 deletions packages/hoc/src/withApollo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ function getDisplayName<P>(WrappedComponent: React.ComponentType<P>) {
return WrappedComponent.displayName || WrappedComponent.name || 'Component';
}

export function withApollo<TProps, TResult = any>(
WrappedComponent: React.ComponentType<
WithApolloClient<Omit<TProps, 'client'>>
>,
export function withApollo<TProps extends WithApolloClient<{}>, TResult = any>(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this fail if someone has given an explicit TProps argument to withApollo that excludes the WithApolloClient part to make the old version work. For example:

type Props = {user: string}
const ExampleC = ({user, client}: WithApolloClient<Props>) => {...}
const Example = withApollo<Props>(ExampleC)

Here, Props does not extend WithApolloClient<{}> and will cause a type error.

WrappedComponent: React.ComponentType<TProps>,
operationOptions: OperationOption<TProps, TResult> = {}
): React.ComponentClass<Omit<TProps, 'client'>> {
const withDisplayName = `withApollo(${getDisplayName(WrappedComponent)})`;
Expand Down Expand Up @@ -53,7 +51,7 @@ export function withApollo<TProps, TResult = any>(
? this.setWrappedInstance
: undefined
});
return <WrappedComponent {...props} />;
return <WrappedComponent {...props as any} />;
}}
</ApolloConsumer>
);
Expand Down