Vuex-persistedstate: Property 'onNuxtReady' does not exist on type 'Window & typeof globalThis'.

Created on 21 Oct 2019  ·  3Comments  ·  Source: robinvdvleuten/vuex-persistedstate

I'm a TypeScript beginner.
I have the problem is "convert JavaScript to TypeScript".
I use Nuxt.

  • JavaScript
import createPersistedState from 'vuex-persistedstate'

export default ({ store, isHMR }) => {
  // In case of HMR, mutation occurs before nuxReady, so previously saved state
  // gets replaced with original state received from server. So, we've to skip HMR.
  // Also nuxtReady event fires for HMR as well, which results multiple registration of
  // vuex-persistedstate plugin
  if (isHMR) return

  if (process.client) {
    window.onNuxtReady((nuxt) => {
      createPersistedState()(store) // vuex plugins can be connected to store, even after creation
    })
  }
}

↓↓↓ TypeScript

import createPersistedState from 'vuex-persistedstate'

export default (obj: { store: object; isHMR: object }) => {
  // In case of HMR, mutation occurs before nuxReady, so previously saved state
  // gets replaced with original state received from server. So, we've to skip HMR.
  // Also nuxtReady event fires for HMR as well, which results multiple registration of
  // vuex-persistedstate plugin
  if (obj.isHMR) return

  if (process.client) {
    window.onNuxtReady((nuxt: object) => {
      createPersistedState()(obj.store) // vuex plugins can be connected to store, even after creation
    })
  }
}
  • ts error
Property 'onNuxtReady' does not exist on type 'Window & typeof globalThis'.

Thank you.

Most helpful comment

It was quite amazing to add the following code.

interface MyWindow extends Window {
  onNuxtReady(obj: object): void
}
declare var window: MyWindow

But I don't think it's optimal.
I would like to know a better solution.

All 3 comments

It was quite amazing to add the following code.

interface MyWindow extends Window {
  onNuxtReady(obj: object): void
}
declare var window: MyWindow

But I don't think it's optimal.
I would like to know a better solution.

The onNuxtReady method is related to Nuxtjs and has nothing to do with this plugin. Please open an issue at their repository or ask it on StackOverflow.

thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rootsli picture rootsli  ·  5Comments

gimyboya picture gimyboya  ·  3Comments

jafri picture jafri  ·  6Comments

syropian picture syropian  ·  6Comments

wiadev picture wiadev  ·  5Comments