-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 error when compiling a module using apollo-client and apollo-cache-inmemory #2503
Comments
Temporary, and unfortunate, workaround is to set |
@tackley thank you for the suggestion. After following the suggestion to set
Below is the client/server code for rendering resulting in the error. The // server.js
export const rootRoute = (req: express.Request, res: express.Response) => {
const location = req.url
const context: AppContext = {}
const client = createApolloServer() // Create ApolloClient
const store: Redux.Store<Store> = configureStore()
const rawHTML = (
<ApolloProvider client={client}> <----ERROR FROM ABOVE HERE
<Provider store={store}> <---- Redux store
<StaticRouter location={location} context={context}>
<Main />
</StaticRouter>
</Provider>
</ApolloProvider>
)
} // client.js
const client = createApolloBrowser()
const history = createHistory()
const store: Redux.Store<Store> = configureStore()
hydrate(
<ApolloProvider client={client}> <----ERROR FROM ABOVE HERE
<Provider store={store}> <---- Redux store
<ConnectedRouter history={history}>
<Main />
</ConnectedRouter>
</Provider>
</ApolloProvider>,
rootNode
) Below are the current set of dependencies:
Thank you team Apollo for all your effort! |
For now you can also set |
@donaldpipowitch still seeing the error. Webpack emits
|
Yeah, same error here |
The issue seems to be that the |
This seems to work together with import { ApolloCache } from 'apollo-cache';
import { InMemoryCache, NormalizedCacheObject } from 'apollo-cache-inmemory';
import { ApolloClient } from 'apollo-client';
import { HttpLink } from 'apollo-link-http';
const client = new ApolloClient({
cache: new InMemoryCache() as ApolloCache<NormalizedCacheObject>,
link: new HttpLink({ uri: '/graphql' }),
});
// ... later ...
<ApolloProvider client={client as ApolloClient<any>}>
{/* ... */}
</ApolloProvider> |
While the return type of the |
Does anyone have an example TS project I can use to test changes and fix this? |
@jbaxleyiii Here's a minimal repository reproducing this bug: https://github.com/AlexanderEkdahl/apollo-client-typescript-bug |
@jbaxleyiii I'm afraid this did not fix the issue. If you clone my repository and then run |
@jbaxleyiii please re-open, just installed everything in a new project ( |
This still happens: https://gist.github.com/prencher/ad626ca0ec21ce8bfc41e4bfcfc54a81 Turning |
@jbaxleyiii It seems like you merged what may be a fix just after the most recent release - assuming that's correct, can we get a patch release, or at least a beta/rc with the fix? |
@prencher we'll follow up on this ASAP - thanks for your patience! |
Am I right to assume that this is still not fixed? I have this code:
and am getting this TS error:
|
@mbrochh new ApolloClient<NormalizedCacheObject>({
ssrMode: typeof window === 'undefined',
link: auth.concat(http),
cache: new InMemoryCache(),
}); |
This is still an issue.
My code
ERROR in /Users/Peter/Workspace/petenelson.dev/src/index.tsx |
For those looking for a great example of next with apollo and typescript, here's the repo that saved me: https://github.com/borisowsky/next-advanced-starter |
This compiles in TypeScript for me import { ApolloClient } from 'apollo-client';
import { InMemoryCache, NormalizedCacheObject } from 'apollo-cache-inmemory';
import { HttpLink } from 'apollo-link-http';
export function createApolloClient(): ApolloClient<NormalizedCacheObject> {
return new ApolloClient({
link: new HttpLink({
uri: "...",
}),
cache: new InMemoryCache(),
});
} |
I fixed it by removing |
This works for me: import { useApolloClient, ApolloClient } from 'apollo-client';
export function getApolloClientInstance(): ApolloClient<object> {
return useApolloClient();
} |
Intended outcome:
Successful compilation of the project.
Actual outcome:
How to reproduce the issue:
tsconfig.json
Sample module:
Version
** Possible cause **
apollo-cache defines
ApolloCache
base class withread
method which cannot miss:apollo-cache-inmemory actually has more realistic definition of the return value as
T | null
The text was updated successfully, but these errors were encountered: