Missing types in subscribe's mutation.events #1117
-
Hello, and thanks for your work on Pinia! Everything seems to be correctly typed, except the With this example: interface State {
selectedInput: number | null;
}
export const useStore = defineStore("main", {
state: (): State => ({
selectedInput: null
}),
useStore().$subscribe((mutation, state) => {
mutation.events.key // ==> Typescript Error: Property 'key' does not exist on type 'DebuggerEvent | DebuggerEvent[]'.
mutation.events.oldValue // ==> Typescript Error: Property 'oldValue' does not exist on type 'DebuggerEvent | DebuggerEvent[]'.
} If i try to call Why can't you infer these types, as they're based on the Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 7 replies
-
Also documentation of |
Beta Was this translation helpful? Give feedback.
-
The reason of your error is actually unrelated to this: the type of |
Beta Was this translation helpful? Give feedback.
This comment was marked as disruptive content.
This comment was marked as disruptive content.
-
this is such a useful feature, why it isn't in production is a bit baffling |
Beta Was this translation helpful? Give feedback.
-
Yes, pls. Add this also to production mode! I've been also caught in this trap now. Very disappointing 😞 |
Beta Was this translation helpful? Give feedback.
-
As noted, this cannot be ported to production because it comes from Vue. One could implement a custom Proxy-based tracking plugin to have this information but it's out of scope of Pinia. The original question isn't even about the |
Beta Was this translation helpful? Give feedback.
mutation.events
is a feature that is only available during development, it won't work in production. It comes from vue watchers (https://vuejs.org/guide/extras/reactivity-in-depth.html#component-debugging-hooks). It's only safe to use this information for devtools plugins .The reason of your error is actually unrelated to this: the type of
mutation.events
isDebuggerEvent | DebuggerEvent[]
, it's sometimes an array, sometimes one single event, that's why you can readmutation.events.key
, you need something likeArray.isArray(mutations.events) ? ... : mutations.events.key