import { ComponentInstance } from '@vue/devtools-api'
import {
GenericStore,
- GenericStoreDefinition,
Method,
StateTree,
Store,
*
* @param stores - list of stores to map to an object
*/
-export function mapStores<Stores extends GenericStoreDefinition[]>(
+export function mapStores<Stores extends any[]>(
...stores: [...Stores]
): Spread<Stores> {
return stores.reduce((reduced, useStore) => {
): MapWritableStateReturn<S> | MapWritableStateObjectReturn<S, KeyMapper> {
return Array.isArray(keysOrMapper)
? keysOrMapper.reduce((reduced, key) => {
+ // @ts-ignore
reduced[key] = {
get(this: ComponentInstance) {
return getCachedStore(this, useStore)[key]
-import {
- defineStore,
- expectType,
- mapStores,
- createPinia,
- GenericStore,
-} from '.'
-
-const useCounter = defineStore({
- id: 'counter',
- state: () => ({ n: 0 }),
-})
-
-type CounterStore = ReturnType<typeof useCounter>
-
-const computedStores = mapStores(useCounter)
-
-expectType<{
- counterStore: () => CounterStore
-}>(computedStores)
+import { expectType, createPinia, GenericStore } from '.'
const pinia = createPinia()