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

Incompatible localForage type #243

Open
udondan opened this issue Oct 24, 2021 · 2 comments
Open

Incompatible localForage type #243

udondan opened this issue Oct 24, 2021 · 2 comments

Comments

@udondan
Copy link

udondan commented Oct 24, 2021

Imported localForage type is not compatible to what vuex-persist expects as storage. How's this meant to be used?

This code

const vuexLocal = new VuexPersistence({
  storage: localForage,
  asyncStorage: true,
});

cannot be compiled:

Type 'LocalForage' is not assignable to type 'Storage | AsyncStorage | undefined'.
Type 'LocalForage' is not assignable to type 'Storage'.
Types of property 'length' are incompatible.
Type '(callback?: ((err: any, numberOfKeys: number) => void) | undefined) => Promise' is not assignable to type 'number'.

Bildschirmfoto 2021-10-24 um 11 22 10

Package versions:

  • vuex-persist: 3.1.3
  • localforage: 1.10.0
@tintin10q
Copy link

I am also wondering about this there is no example given.

@shamscorner
Copy link

If you see the error message, you can see the Type LocalForage is not assignable to type Storage | AsyncStorage | undefined. So that means it has to be one of these three types. LocalForage is asynchronous by its nature. Hence you have to typecast to AsyncStorage like below,

import VuexPersistence, { AsyncStorage } from 'vuex-persist';
. . .

const vuexLocal = new VuexPersistence<RootState>({
  storage: localForage as AsyncStorage,
  asyncStorage: true,
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants