TypeScript function signature help #1691
-
Hi all! I'm writing a function that allows me to sync prop values to a Pinia store. It looks like this when used: const userStore = useUserStore()
const authorizationsStore = useAuthorizationsStore()
useSyncValuesToStores(
[userStore, 'user', computed(() => props.user)],
[authorizationsStore, 'abilities', computed(() => props.abilities)],
) It essentially accepts an array of tuples where the tuple is typed as: type SyncTuple<TStore extends Store, TKey extends keyof TStore['$state']> = [TStore, TKey, ComputedRef<TStore[TKey]>] How can I type the Obviously this won't work: export const useSyncValuesToStores = (...mappings: SyncTuple[]): void => {
console.log(mappings);
} as Here's a minimal repro in the TS Playground |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Turns out i was very close! The |
Beta Was this translation helpful? Give feedback.
Turns out i was very close! The
mappedStoreTuples
just didn't need to extendany[]
!Updated TS playground