Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript definition problems with apollo-client@next and link-core / cache-core #2212

Closed
lordnox opened this issue Sep 26, 2017 · 12 comments
Closed
Assignees
Milestone

Comments

@lordnox
Copy link

lordnox commented Sep 26, 2017

screen shot 2017-09-26 at 11 01 45
Code in question:


import ApolloClient from 'apollo-client'
import HttpLink from 'apollo-link-http'
import InMemoryCache from 'apollo-cache-inmemory'

const link = new HttpLink({
  uri: 'https://graphql-pokemon.now.sh',
})

const cache = new InMemoryCache()

export const client = new ApolloClient({
  cache,
  link,
})

Intended outcome:
This code is mostly copied from apollo-client-preset and I expected it to work out of the box. I might be missing some parameters for the cache, but typescript did not like the code even without the cache

Actual outcome:
Typescript complains about:

  • Types of property 'cache' are incompatible
    Type 'InMemoryCache' is not assignable to type 'ApolloCache<{}>
    Property 'write' is missing in type 'InMemoryCache'.

How to reproduce the issue:
The code in the beginning should produce the error

Version

@jbaxleyiii jbaxleyiii self-assigned this Sep 27, 2017
@jbaxleyiii jbaxleyiii added this to the 2.0 milestone Sep 27, 2017
@jbaxleyiii
Copy link
Contributor

@lordnox can you try with the latest betas?

Also the Cache will need a type of the store now

@katopz
Copy link
Contributor

katopz commented Oct 12, 2017

In my case

package.json

  "dependencies": {
    "apollo-client-preset": "^0.2.0-beta.8",
    "react": "^16.0.0",
    "react-apollo": "^2.0.0-beta.0",
    "react-dom": "^16.0.0",
    "react-scripts-ts": "2.7.0",
    "redux": "^3.7.2"
  },
  "devDependencies": {
    "@types/jest": "^21.1.2",
    "@types/node": "^8.0.34",
    "@types/react": "^16.0.10",
    "@types/react-dom": "^16.0.1"
  }

index.tsx

import * as React from 'react';
import { render } from 'react-dom';

import ApolloClient from 'apollo-client';
import { HttpLink, InMemoryCache } from 'apollo-client-preset';
import { ApolloProvider } from 'react-apollo';

import App from './App';

const GRAPHQL_END_POINT = 'SOME_ENDPOINT';

const client = new ApolloClient({
  link: new HttpLink({ uri: GRAPHQL_END_POINT }),
  cache: (new InMemoryCache()).restore({})
});

const WrappedApp = (
  <ApolloProvider client={client}>
    <App />
  </ApolloProvider>
);

render(WrappedApp, document.getElementById('root'));

Error

(22,21): error TS2322: Type '{ client: ApolloClient<NormalizedCache>; children: Element; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<ApolloProvider> & Readonly<{ children?: ReactNode;...'.
  Type '{ client: ApolloClient<NormalizedCache>; children: Element; }' is not assignable to type 'Readonly<ProviderProps<Cache>>'.
    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'.

@mzygmunt
Copy link

@katopz The same error with version apollo-client 2.0.1 and react-apollo 2.0.0

@Jannis
Copy link

Jannis commented Nov 2, 2017

This seems closely related (or identical even) to apollographql/react-apollo#1299.

@jbaxleyiii
Copy link
Contributor

Looks like someone took a stab at it here which I'm working to release asap! Hopefully it fixes these issues!

@prencher
Copy link

Is there any traction on this? We just tried to upgrade our codebase today and ran into this with the latest versions.

@jbaxleyiii I don't see how the ApolloProvider change would address this. The issue is with ApolloClient and InMemoryCache.

@alvis
Copy link

alvis commented Nov 18, 2017

@prencher the code in #1319 hasn't released yet, so that may be the reason the issue remains. May be you can try the master version for now. Disclaimer: I haven't tried it yet.

@iamclaytonray
Copy link

@jbaxleyiii - Any word on when this will be released?

@katopz
Copy link
Contributor

katopz commented Dec 26, 2017

@iamclaytonray Seem working for me now, do try here https://github.com/katopz/apollo-client-preset-ts-example

@evenfrost
Copy link

Any update on this?

@iamclaytonray
Copy link

I can verify that the latest release fixes this problem. (Probably the release before latest as well. I haven't touched that project in about a couple of months.)

@hwillson
Copy link
Member

This issue has been resolved (verified with apollo-client 2.3.1). Thanks!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants