Apollo-client: onResetStore typing error

Created on 13 May 2019  路  3Comments  路  Source: apollographql/apollo-client

The code from docs:
https://www.apollographql.com/docs/react/essentials/local-state#cache-initialization

import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';

const cache = new InMemoryCache();
const client = new ApolloClient({
  cache,
  resolvers: { /* ... */ },
});

const data = {
  todos: [],
    visibilityFilter: 'SHOW_ALL',
    networkStatus: {
      __typename: 'NetworkStatus',
      isConnected: false,
  },
};

cache.writeData({ data });

client.onResetStore(() => cache.writeData({ data }));

This line causes error in typescript:
client.onResetStore(() => cache.writeData({ data }))

TypeScript error: Type 'void' is not assignable to type 'Promise<any>'.  TS2322

Most helpful comment

Try client.onResetStore(async () => cache.writeData({ data }));

All 3 comments

Try client.onResetStore(async () => cache.writeData({ data }));

Try client.onResetStore(async () => cache.writeData({ data }));

I was having this issue, and adding async solved it for me.

Sounds like this was resolved - closing, thanks!

Was this page helpful?
0 / 5 - 0 ratings