]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
refactor: use correct type import
authorEduardo San Martin Morote <posva13@gmail.com>
Sun, 2 May 2021 19:25:50 +0000 (21:25 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Sun, 2 May 2021 19:25:50 +0000 (21:25 +0200)
src/mapHelpers.ts

index d7a9ac4c4e9b5b7170adacd9f90ff7ed701094ca..be8472b0ce8b2937f0c8f455ec7c9bb56f82f922 100644 (file)
@@ -1,4 +1,4 @@
-import { ComponentInstance } from '@vue/devtools-api'
+import { ComponentPublicInstance } from 'vue'
 import {
   GenericStore,
   GettersTree,
@@ -52,10 +52,10 @@ function getCachedStore<
   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>
 }
@@ -248,13 +248,13 @@ export function mapState<
 ): 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
@@ -368,13 +368,19 @@ export function mapActions<
 ): 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
@@ -455,10 +461,10 @@ export function mapWritableState<
     ? 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)
           },
@@ -468,10 +474,10 @@ export function mapWritableState<
     : 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]