0

I am using pinia with nuxt and typescript to create stores.

This is code of auth store (with nuxt auth module) -

import { defineStore } from 'pinia';

export const useAuthStore = defineStore('authStore', {
  getters: {
     isAuthenticated(state) {
       return state.$nuxt.$auth.loggedIn
     }
  }
})

Now the issue is, IDE gives typescript error -

Property '$nuxt' does not exist on type '{} and {}'. ts(2339)

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129

1 Answers1

0

state.$nuxt tries to access a state property named $nuxt which does not exist (unless you create it yourself). The pinia docs say that $nuxt is injected into the store, so you should be able to access it via this.$nuxt.

dr_barto
  • 5,723
  • 3
  • 26
  • 47