Within my Pinia-based store, I have state with the following properties:
import { defineStore } from 'pinia'
import { ref } from 'vue'
export const useLoginStore = defineStore('login', () => {
// State
const isAuthenticated = useLocalStorage('isAuthenticated', false)
const user = ref<{ name: string; email: string } | null>(null)
const accessToken = ref<string | null>(null);
// Actions
const login = (userData: { name: string; email: string }, token: string) => {
user.value = userData
isAuthenticated.value = true
accessToken.value = token
}
const logout = () => {
user.value = null
isAuthenticated.value = false
accessToken.value = null;
}
return {
isAuthenticated,
user,
accessToken,
login,
logout,
}
})
Referring to the VueUse documentation, I made adjustments to the initial value as per its simple type inference, however, I am struggling to explicitly specify more complex type annotations:
...
// State
const isAuthenticated = useLocalStorage('isAuthenticated', false)
const user = ???
const accessToken = ???
...
UPDATE: included the complete Pinia store for better understanding