Open rostamiani opened 4 years ago
I tried to use it like this, but have errors:
import {
Module,
VuexModule,
Mutation,
Action,
getModule,
} from 'vuex-module-decorators'
import Vuex from 'vuex'
import Vue from 'vue'
export interface RootState {
count: number
}
@Module
class TestModule extends VuexModule {
count = 0
@Mutation
increment(delta: number) {
this.count += delta
}
// action 'incr' commits mutation 'increment' when done with return value as payload
@Action({ commit: 'increment' })
incr() {
return 5
}
}
// Error:
// Argument of type 'TestModule' is not assignable to parameter of type 'ConstructorOf<VuexModule<ThisType<any>, any>>'.
const testModule = getModule(TestModule.prototype)
Vue.use(Vuex)
export const store = new Vuex.Store<RootState>({
modules: {
testModule,
},
})
// Error:
// Argument of type 'Store<RootState>' is not assignable to parameter of type 'ConstructorOf<VuexModule<ThisType<any>, any>>'.
const TStore = getModule(store)
How can I access the getModule without NuxtJS? I'm using Vuejs. How can I access store states and actions with types? Do I have to have NuxtJS to use getModule?
Why getModule just used in the NustJS examples? Is it a good idea to export getModule(store) in the store/index.ts? Why this isn't done in the examples?
like this: