Adding ref to state from action #673
-
I've seen the doc that mentions how a plugin can add a ref to a store's state: https://pinia.esm.dev/core-concepts/plugins.html#adding-new-state. I am trying to do the same thing but from an action instead: type AuthStoreState = {
user: CurrentUserQuery['currentUser'] | null
}
export const useAuthStore = defineStore('auth', {
state: (): AuthStoreState => ({ user: null }),
getters: {},
actions: {
async authenticate(email: string, password: string) {
/* authentication code omitted for brevity */
const { result: currentUserResult } = useCurrentUserQuery()
const user = useResult(currentUserResult) // Ref<CurrentUserQuery['currentUser']>
this.user = user // TS complains
this.$state.user = user // TS complains here too
}
}
}) Is this just a TS issue? Is there a way to do this without having to manage the ref myself? |
Beta Was this translation helpful? Give feedback.
Answered by
posva
Nov 18, 2021
Replies: 1 comment 1 reply
-
Yeah, this is just a TS issue. Now that TS accepts different getters and setters for properties, this can be achieved |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It actually depends on microsoft/TypeScript#43826