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

index 6d6f31f5214e80e203d679fe57f0f96d186f79c9..cc894750f331799556aeb83e1d2dca619784e063 100644 (file)
@@ -3,10 +3,11 @@ import { createLocalVue, mount } from '@vue/test-utils'
 import Vue from 'vue'
 
 declare module '../src' {
-  export interface PiniaCustomProperties {
+  export interface PiniaCustomProperties<Id> {
     n: number
     // uid: App['_uid']
     hasPinia: boolean
+    idFromPlugin: Id
   }
 }
 
@@ -44,6 +45,8 @@ describe('store plugins', () => {
     expect(store.n).toBe(20)
     // @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 7c7af92f55b8cdad020ca6390971a0cda0b721e5..b707f1939dfcb41d567ac1cb74ff649ec83b83ad 100644 (file)
@@ -113,7 +113,7 @@ export type Store<
   S &
   StoreWithGetters<G> &
   StoreWithActions<A> &
-  PiniaCustomProperties
+  PiniaCustomProperties<Id, S, G, A>
 
 export type GenericStore = Store<
   string,
@@ -147,4 +147,9 @@ declare global {
  * Properties that are added to every store by `pinia.use()`
  */
 // eslint-disable-next-line
-export interface PiniaCustomProperties {}
+export interface PiniaCustomProperties<
+  Id extends string = string,
+  S extends StateTree = StateTree,
+  G = Record<string, Method>,
+  A = Record<string, Method>
+> {}