-import { ComponentInstance } from '@vue/devtools-api'
+import { ComponentPublicInstance } from 'vue'
import {
GenericStore,
GettersTree,
G extends GettersTree<S> = GettersTree<S>,
A = Record<string, Method>
>(
- vm: ComponentInstance,
+ vm: ComponentPublicInstance,
useStore: StoreDefinition<Id, S, G, A>
): Store<Id, S, G, A> {
- const cache = '_pStores' in vm ? vm._pStores : (vm._pStores = {})
+ const cache = '_pStores' in vm ? vm._pStores! : (vm._pStores = {})
const id = useStore.$id
return (cache[id] || (cache[id] = useStore(vm.$pinia))) as Store<Id, S, G, A>
}
): MapStateReturn<S, G> | MapStateObjectReturn<Id, S, G, A, KeyMapper> {
return Array.isArray(keysOrMapper)
? keysOrMapper.reduce((reduced, key) => {
- reduced[key] = function (this: ComponentInstance) {
+ reduced[key] = function (this: ComponentPublicInstance) {
return getCachedStore(this, useStore)[key]
} as () => any
return reduced
}, {} as MapStateReturn<S, G>)
: Object.keys(keysOrMapper).reduce((reduced, key: keyof KeyMapper) => {
- reduced[key] = function (this: ComponentInstance) {
+ reduced[key] = function (this: ComponentPublicInstance) {
const store = getCachedStore(this, useStore)
const storeKey = keysOrMapper[key]
// for some reason TS is unable to infer the type of storeKey to be a
): MapActionsReturn<A> | MapActionsObjectReturn<A, KeyMapper> {
return Array.isArray(keysOrMapper)
? keysOrMapper.reduce((reduced, key) => {
- reduced[key] = function (this: ComponentInstance, ...args: any[]) {
+ reduced[key] = function (
+ this: ComponentPublicInstance,
+ ...args: any[]
+ ) {
return (getCachedStore(this, useStore)[key] as Method)(...args)
} as Store<string, StateTree, {}, A>[keyof A]
return reduced
}, {} as MapActionsReturn<A>)
: Object.keys(keysOrMapper).reduce((reduced, key: keyof KeyMapper) => {
- reduced[key] = function (this: ComponentInstance, ...args: any[]) {
+ reduced[key] = function (
+ this: ComponentPublicInstance,
+ ...args: any[]
+ ) {
return getCachedStore(this, useStore)[keysOrMapper[key]](...args)
} as Store<string, StateTree, {}, A>[keyof KeyMapper[]]
return reduced
? keysOrMapper.reduce((reduced, key) => {
// @ts-ignore
reduced[key] = {
- get(this: ComponentInstance) {
+ get(this: ComponentPublicInstance) {
return getCachedStore(this, useStore)[key]
},
- set(value) {
+ set(this: ComponentPublicInstance, value) {
// it's easier to type it here as any
return (getCachedStore(this, useStore)[key] = value as any)
},
: Object.keys(keysOrMapper).reduce((reduced, key: keyof KeyMapper) => {
// @ts-ignore
reduced[key] = {
- get(this: ComponentInstance) {
+ get(this: ComponentPublicInstance) {
return getCachedStore(this, useStore)[keysOrMapper[key]]
},
- set(value) {
+ set(this: ComponentPublicInstance, value) {
// it's easier to type it here as any
return (getCachedStore(this, useStore)[
keysOrMapper[key]