Intended outcome:
Upgrading from 1.x release to the 2.x release.
Actual outcome:
Types of property 'client' are incompatible.
Type 'ApolloClient<NormalizedCache>' is not assignable to type 'ApolloClient<Cache>'.
Type 'NormalizedCache' is not assignable to type 'Cache'.
Property 'add' is missing in type 'NormalizedCache'.
How to reproduce the issue:
Install react apollo in a typescript project and run tsc
Version
Rather than using the Cache type, which is defined in the TypeScript lib.dom.d.ts declaration file, for the generic parameter to ProviderProps in the ApolloProvider class, it may be more appropriate to use any to let the type flow through when the client is created. It may also be less confusing if the generic type parameter was renamed to something like TCache in the ProviderProps interface definition so it's not confused with the Cache type.
I tested this change in the ApolloProvider.d.ts file and noticed the error went away and the client was properly typed as NormalizedCache when defining the cache as InMemoryCache.
@corydeppen thanks, this worked! Can you make a pull request?
Who's in charge of deciding how this gets fixed? I'm also hitting this with
"apollo-cache-inmemory": "^1.0.0",
"apollo-client": "^2.0.1",
"apollo-link-http": "^1.1.0",
"apollo-link-state": "^0.0.4",
"graphql": "^0.11.7",
"graphql-tag": "^2.5.0",
"react-apollo": "2.0.0",
This issue has been automatically labled because it has not had recent activity. If you have not received a response from anyone, please mention the repository maintainer (most likely @jbaxleyiii). It will be closed if no further activity occurs. Thank you for your contributions to React Apollo!
This issue has been automatically closed because it has not had recent activity after being marked as no recent activyt. If you belive this issue is still a problem or should be reopened, please reopen it! Thank you for your contributions to React Apollo!
Most helpful comment
Rather than using the
Cachetype, which is defined in the TypeScriptlib.dom.d.tsdeclaration file, for the generic parameter toProviderPropsin theApolloProviderclass, it may be more appropriate to useanyto let the type flow through when the client is created. It may also be less confusing if the generic type parameter was renamed to something likeTCachein theProviderPropsinterface definition so it's not confused with theCachetype.I tested this change in the
ApolloProvider.d.tsfile and noticed the error went away and the client was properly typed asNormalizedCachewhen defining the cache asInMemoryCache.