From 36129cf415abb8efccda859cd6b787594fe46f00 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 31 Mar 2021 19:30:29 +0200 Subject: [PATCH] feat(types): generics on PiniaCustomProperties --- __tests__/storePlugins.spec.ts | 5 ++++- src/types.ts | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) 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 +> {} -- 2.47.2