volna
volna

Reputation: 2610

What is proper type for vuex store returned to the vuex plugin during it initialisation

The store initialisation is being done the following way:

/* Logic */
import Vue from 'vue'
import Vuex, { StoreOptions } from 'vuex'

Vue.use(Vuex)

const DataManager = new UserDataManager()

type RootStateType = {
  version: string
}

const store: StoreOptions<RootStateType> = {
  // @ts-ignore
  state: {
    version: '1.0.0'
  },
  modules: {...},
  plugins: [DataManager.init()]
}

export default new Vuex.Store<RootStateType>(store)

...while the plugin:

export class UserDataManager {
  ... logic

  public init () {
    return (store: <TYPE?>) => {
      store.watch(
        (state: RootStateType) => {
          return [state.user.authentication.id]
        },
        (watched: string[]) => {
          const userID = watched[0]
          ... logic
        }
      )
    }
  }
}

I am a bit puzzled if somehow the proper type can be passed here? I've tried passing to it:

type storeType = StoreOptions<RootStateType>

...
    return (store: storeType) => {
...

but it returns: TS2339: Property 'watch' does not exist on type 'StoreOptions<RootStateType>' I will appreciate a lot if somebody can share some ideas on this topic :-)

Upvotes: 0

Views: 72

Answers (1)

Alex Brohshtut
Alex Brohshtut

Reputation: 2060

Peeked at vuex-persist, and Store<RootStateType> should work.

Upvotes: 1

Related Questions