Destructuring the store and type inference #406
-
1st I must say BIG thanks for creating this project. It has soo much better API than Vuex ! My question is about destructuring stores. In case I want to "drill down" into the store and just pass a single property to my component , I do this: const { user } = toRefs(store) The code works perfectly BUT VS Code + Vetur somehow does not like it. When I hover over Just want to be sure this is correct way how to "split" the store .... THX |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Doing const user = toRef(store, 'user')
// or
const { user } = toRefs(store) is correct but it seems like only the first one is correctly inferred while the second is not. This seems to be a bug on Vue types: // this is the current version
declare function toRefs<T extends Data = Data>(obj: T): ToRefs<T>;
// this one works
declare function toRefs<T = Data>(obj: T): ToRefs<T>; There might be an open PR already |
Beta Was this translation helpful? Give feedback.
-
Also, I'm happy you enjoy using Pinia! |
Beta Was this translation helpful? Give feedback.
Doing
is correct but it seems like only the first one is correctly inferred while the second is not. This seems to be a bug on Vue types:
There might be an open PR already