championswimmer / vuex-persist

A Vuex plugin to persist the store. (Fully Typescript enabled)
http://championswimmer.in/vuex-persist
MIT License
1.67k stars 117 forks source link

No longer works with upgraded Vue and Vuex #132

Open nmummau opened 5 years ago

nmummau commented 5 years ago

I am using vuex-persist@2.0.1

I recently upgraded vue and vuex. vue@2.6.10 vuex@3.1.0

Before the upgrade I had vuex-persist working perfectly, in my typescript project, with the provided documentation. After the upgrade, I now get an error in my Store. Here is my code:

const vuexAllModules = new VuexPersistence({
    storage: window.localStorage
});

export default new Vuex.Store<RootState>({
    strict: !config.isProd,
    modules: {
        module1,
        module2
    },
    state: {},
    getters: {},
    mutations: {},
    actions: {},
    plugins: [vuexAllModules.plugin] // <<<<-----SOURCE OF ERROR
});

ERROR

Type 'Plugin<unknown>[]' is not assignable to type 'Plugin<RootState>[]'.
  Type 'Plugin<unknown>' is not assignable to type 'Plugin<RootState>'.
    Types of parameters 'store' and 'store' are incompatible.
      Type 'Store<RootState>' is not assignable to type 'Store<unknown>'.
        Types of property 'registerModule' are incompatible.
          Type '{ <T>(path: string, module: Module<T, RootState>, options?: ModuleOptions | undefined): void; <T>(path: string[], module: Module<T, RootState>, options?: ModuleOptions | undefined): void; }' is not assignable to type '{ <T>(path: string, module: Module<T, unknown>, options?: ModuleOptions | undefined): void; <T>(path: string[], module: Module<T, unknown>, options?: ModuleOptions | undefined): void; }'.
            Types of parameters 'module' and 'module' are incompatible.
              Type 'Module<any, unknown>' is not assignable to type 'Module<any, RootState>'.
                Types of property 'actions' are incompatible.
                  Type 'ActionTree<any, unknown> | undefined' is not assignable to type 'ActionTree<any, RootState> | undefined'.
                    Type 'ActionTree<any, unknown>' is not assignable to type 'ActionTree<any, RootState>'.
                      Index signatures are incompatible.
                        Type 'Action<any, unknown>' is not assignable to type 'Action<any, RootState>'.
                          Type 'ActionHandler<any, unknown>' is not assignable to type 'Action<any, RootState>'.
                            Type 'ActionHandler<any, unknown>' is not assignable to type 'ActionHandler<any, RootState>'.
                              Type 'unknown' is not assignable to type 'RootState'.ts(2322)
index.d.ts(96, 3): The expected type comes from property 'plugins' which is declared here on type 'StoreOptions<RootState>'
martijnboland commented 5 years ago

Try adding the generic parameter RootState to the VuexPersistence consructor

const vuexAllModules = new VuexPersistence<RootState>({

That worked for us

morficus commented 4 years ago

I think this is a TS issue. I'm using Vue 2.6.10 and Vuex 3.1.1 with the latest version of this plugin and I have no issues.

RamsesMartinez commented 4 years ago

Try adding the generic parameter RootState to the VuexPersistence consructor

const vuexAllModules = new VuexPersistence<RootState>({

That worked for us

Thanks, is simple issue, this helps me :D

MikeyBeLike commented 4 years ago

Try adding the generic parameter RootState to the VuexPersistence consructor

const vuexAllModules = new VuexPersistence<RootState>({

That worked for us

Thanks worked for me too

nthx commented 4 years ago

Check also if typescript was upgraded as well. It might be due to changes in it. For me it helped to downgrade typescript from 3.7. to 3.4.x (3.5.x introduced this error)