What is the proper typing for a Store instance? #499
-
Note: I'm currently using I'm working on a small custom composable thats purpose is to take a prop passed to a component, and set the store data with that prop's value: import { watch } from 'vue'
import type { Store } from 'pinia'
export const useSyncValueToStore = <
TStore extends Store,
TKey extends keyof TStore
>(
propGetter: () => TStore[TKey],
store: TStore,
key: TKey
): void => {
watch(
propGetter,
propValue => {
store[key] = propValue
},
{
immediate: true,
}
)
} That would get used like so: useSyncValueToStore(() => props.user, userStore, 'user') So basically: Take Unfortunately, TS is complaining about
So what's the correct way to type the store instance in this case? |
Beta Was this translation helpful? Give feedback.
Answered by
posva
May 17, 2021
Replies: 1 comment 3 replies
-
I think this is a bug |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
posva
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think this is a bug