Open async3619 opened 5 years ago
I got this error too, can u share your solution
the problem in my project is type error,so I try to
class MyMeeting xxx
export default withApollo(MyMeeting as any)
not elegantly but usefull
@arieslx I've redeclared whole withApollo function definition like this:
import React from "react";
import { OperationOption, withApollo as withApolloImpl } from "react-apollo";
import { ApolloClient } from "apollo-client";
export declare type WithApolloClient<P> = P & {
client: ApolloClient<any>;
};
export function withApollo<TProps extends WithApolloClient<{}>, TResult = any>(
WrappedComponent: React.ComponentType<TProps>,
operationOptions?: OperationOption<TProps, TResult>,
): React.ComponentClass<Omit<TProps, "client">> {
return withApolloImpl(WrappedComponent as any, operationOptions);
}
If anyone wants to submit a PR that fixes this, we'll definitely review it - thanks!
I don't want to put the blame on anybody but my issue opened almost 6 months ago. I'm really shameful about I don't know how to open pull request even if I'm using git like 2 years.
I don't think this is a big problem/issue (or bug) that break something that working with this module but I think we should care about type errors
since this module written on typescript.
Funnily enough, I don't even know whether if this error still occurring with latest typescript version or not. 😂 and I respect all the people who contributed to the project, and I didn't write this comment aggressively either. I hope you guys don't misunderstand my purpose.
...so any updates on this issue?
So I had been following this issue for a while, I managed to work around it by doing the following:
import React from "react";
interface MyProps {
something: boolean;
}
const MyComponent = ( props : WithApolloClient<MyProps> ) => {
const x = client.query( ... );
return ...
}
export default withApollo<MyProps>( MyComponent );
I have since moved on from this ugly approach to just using the hook:
import React from "react";
import { useApolloClient } from "react-apollo";
interface MyProps {
something: boolean;
}
const MyComponent = ( props : MyProps ) => {
const client = useApolloClient();
const x = client.query( ... );
return ...
}
export default MyComponent;
Intended outcome:
First of all, I'd like to apologize my poor english skill. I'll have some time for fixing this poor-english-skill issue first. 😬
When we use
withApollo
HOC, it should return a new component type withoutclient
property atprops
type like below:Actual outcome:
But above code snippet with latest apollo release won't exclude
client
prop in originalprops
type.I thought it's just an error just because there's no properties at generic argument of
WithApolloClient
, but It made an error atwithApollo(Foo)
.I checked type definition of
withApollo
HOC and I found a problem:Firstly, see (1). We're already expecting that generic
TProps
should haveclient
property. so I think we shouldn't useWithApolloClient
as prop type ofWrappedComponent
parameter since TProps would have it.I don't get why we omit
client
property ofTProps
even if we'll add it again withWithApolloClient
. Are there any reasons?and see (2). we don't know whether if generic
TProps
would haveclient
property or not sinceTProps
isn't extending anything. It can accept literally any types and I think that's why prop type of returned component will haveunknown
.so I think the approach of this issue would be like this:
with above definition, we enforce
TProps
generic havingclient
property as required one. and just remove it from returned component type. I'm not sure above approach is perfect or not but I believe current one is wrong.How to reproduce the issue:
Version
FYI, I'm using typescript 3.5.3 now.