question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Async Storage with localForage .restored not available.

See original GitHub issue

Currently, we have an older project that we are migrating from javascript to typescript. Implemented typescript router but still using javascript store. Tried npm install @types/vuex-persist with no such package available.

Ended up adding vuex-persist.d.ts, which solved the problem:

import Vue, { VNode } from 'vue'
 import { Store } from 'vuex'
 
declare module 'vuex' {
    export interface Store<S> {
         restored: Promise<S>
     }
}

Is there a possibility to include types for future users that may experience the same problem?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

1reaction
BasNijhuiscommented, Apr 24, 2020

Same issue here, temporary fixed it like so:

// hacky solution since type declartion for restored is missing in vuex-persist
// waits for IndexedDB (localForage) to be loaded into vuex so mutations aren't overridden on start up
await ((store as unknown) as { restored: Promise<unknown> }).restored;
0reactions
jacobcorocommented, Aug 1, 2020

This stopped working for some reason, but I got it back by doing

await (store as any).original.restored; in my router guard

and restoreState: key => localForage.getItem(key), in const vuexLocalForage = new VuexPersistence<RootState>({

Read more comments on GitHub >

github_iconTop Results From Across the Web

React native async storage issues - Stack Overflow
Try using JSON.parse() when getting and JSON.stringify() when setting it.
Read more >
How to use the localforage.setDriver function in ... - Snyk
setDriver('objectStorage') const vuexPersist = new VuexPersistence<any>({ key: 'restored_test', asyncStorage: true, storage: localForage, reducer: (state) ...
Read more >
Cory House on Twitter: "Just learned about localforage - Twitter
Just learned about localforage - An npm package that makes it easy to store data ... Async/await Unlike localStorage, you can store any...
Read more >
@feathersjs-offline/client - npm
There are no other projects in the npm registry using ... stores data in localStorage in the browser or AsyncStorage in React Native....
Read more >
How to Use localForage for Easy Async Browser Storage
IndexedDB; WebSQL; localStorage. It will gracefully degrade if that database isn't available. For example, WebSQL isn't available on Firefox ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found