]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
feat(types): generics on PiniaCustomProperties
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 31 Mar 2021 17:30:29 +0000 (19:30 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 31 Mar 2021 17:30:29 +0000 (19:30 +0200)
__tests__/storePlugins.spec.ts
src/types.ts

index 25508c742d4f6b72f82d34603ca78971425666b5..0f7a1b45921295db2716bf99c79f8723c8c314ac 100644 (file)
@@ -3,10 +3,11 @@ import { mount } from '@vue/test-utils'
 import { App } from 'vue'
 
 declare module '../src' {
-  export interface PiniaCustomProperties {
+  export interface PiniaCustomProperties<Id> {
     n: number
     uid: App['_uid']
     hasApp: boolean
+    idFromPlugin: Id
   }
 }
 
@@ -42,6 +43,8 @@ describe('store plugins', () => {
     expect(store.uid).toBeDefined()
     // @ts-expect-error: n is a number
     store.n.notExisting
+    // @ts-expect-error: it should always be 'test'
+    store.idFromPlugin == 'hello'
   })
 
   it('can install plugins before installing pinia', () => {
index 9e72b1444a0b9bb309b83d7f346e29e46280b319..d58de224e5db2dffb25b5f71edddb36f3f35caaa 100644 (file)
@@ -140,7 +140,7 @@ export type Store<
   S &
   StoreWithGetters<G> &
   StoreWithActions<A> &
-  PiniaCustomProperties
+  PiniaCustomProperties<Id, S, G, A>
 
 /**
  * Generic store type
@@ -155,4 +155,9 @@ export type GenericStore = Store<
 /**
  * Properties that are added to every store by `pinia.use()`
  */
-export interface PiniaCustomProperties {}
+export interface PiniaCustomProperties<
+  Id extends string = string,
+  S extends StateTree = StateTree,
+  G = Record<string, Method>,
+  A = Record<string, Method>
+> {}