From: Eduardo San Martin Morote Date: Wed, 31 Mar 2021 17:30:29 +0000 (+0200) Subject: feat(types): generics on PiniaCustomProperties X-Git-Tag: v2.0.0-alpha.10~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=36129cf415abb8efccda859cd6b787594fe46f00;p=thirdparty%2Fvuejs%2Fpinia.git feat(types): generics on PiniaCustomProperties --- diff --git a/__tests__/storePlugins.spec.ts b/__tests__/storePlugins.spec.ts index 25508c74..0f7a1b45 100644 --- a/__tests__/storePlugins.spec.ts +++ b/__tests__/storePlugins.spec.ts @@ -3,10 +3,11 @@ import { mount } from '@vue/test-utils' import { App } from 'vue' declare module '../src' { - export interface PiniaCustomProperties { + export interface PiniaCustomProperties { 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', () => { diff --git a/src/types.ts b/src/types.ts index 9e72b144..d58de224 100644 --- a/src/types.ts +++ b/src/types.ts @@ -140,7 +140,7 @@ export type Store< S & StoreWithGetters & StoreWithActions & - PiniaCustomProperties + PiniaCustomProperties /** * 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, + A = Record +> {}