From: Eduardo San Martin Morote Date: Wed, 31 Mar 2021 17:30:46 +0000 (+0200) Subject: feat(types): generic on PiniaCustomProperties X-Git-Tag: v0.2.5~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9fedc045af8d1cdb57f805a9457557fc905df8d6;p=thirdparty%2Fvuejs%2Fpinia.git feat(types): generic on PiniaCustomProperties --- diff --git a/__tests__/storePlugins.spec.ts b/__tests__/storePlugins.spec.ts index 6d6f31f5..cc894750 100644 --- a/__tests__/storePlugins.spec.ts +++ b/__tests__/storePlugins.spec.ts @@ -3,10 +3,11 @@ import { createLocalVue, mount } from '@vue/test-utils' import Vue from 'vue' declare module '../src' { - export interface PiniaCustomProperties { + export interface PiniaCustomProperties { 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', () => { diff --git a/src/types.ts b/src/types.ts index 7c7af92f..b707f193 100644 --- a/src/types.ts +++ b/src/types.ts @@ -113,7 +113,7 @@ export type Store< S & StoreWithGetters & StoreWithActions & - PiniaCustomProperties + PiniaCustomProperties 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, + A = Record +> {}