I'm a TypeScript beginner.
I have the problem is "convert JavaScript to TypeScript".
I use Nuxt.
JavaScriptimport 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 errorProperty 'onNuxtReady' does not exist on type 'Window & typeof globalThis'.
Thank you.
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
Most helpful comment
It was quite amazing to add the following code.
But I don't think it's optimal.
I would like to know a better solution.