From: Eduardo San Martin Morote Date: Wed, 31 Mar 2021 09:56:44 +0000 (+0200) Subject: fix(types): add PiniaCustomProperties to stores X-Git-Tag: v0.2.3~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a12d96db6d981d4af023360018bd1c6a6658ff8e;p=thirdparty%2Fvuejs%2Fpinia.git fix(types): add PiniaCustomProperties to stores --- diff --git a/__tests__/storePlugins.spec.ts b/__tests__/storePlugins.spec.ts index fb62ccfa..62bb11ee 100644 --- a/__tests__/storePlugins.spec.ts +++ b/__tests__/storePlugins.spec.ts @@ -28,6 +28,8 @@ describe('store plugins', () => { const store = useStore(pinia) expect(store.n).toBe(20) + // @ts-expect-error: n is a number + store.n.notExisting }) it('can install plugins before installing pinia', () => { diff --git a/src/index.ts b/src/index.ts index 1da08104..50217f25 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,6 @@ export { createPinia, Pinia, PiniaStorePlugin, - PiniaCustomProperties, } from './rootStore' export { defineStore } from './store' export { PiniaPlugin } from './plugin' @@ -13,5 +12,8 @@ export { StoreWithGetters, StoreWithActions, StoreWithState, + PiniaCustomProperties, } from './types' + +// TODO: remove in beta export { createStore } from './deprecated' diff --git a/src/rootStore.ts b/src/rootStore.ts index 438cebd9..850edbcb 100644 --- a/src/rootStore.ts +++ b/src/rootStore.ts @@ -1,5 +1,10 @@ import { InjectionKey, ref, Ref } from '@vue/composition-api' -import { StateTree, StoreWithState, StateDescriptor } from './types' +import { + StateTree, + StoreWithState, + StateDescriptor, + PiniaCustomProperties, +} from './types' import { VueConstructor } from 'vue' import type Vue from 'vue' @@ -14,12 +19,6 @@ export const storesMap = new WeakMap< Map, StateDescriptor]> >() -/** - * Properties that are added to every store by `pinia.use()` - */ -// eslint-disable-next-line -export interface PiniaCustomProperties {} - export const piniaSymbol = (__DEV__ ? Symbol('pinia') : /* istanbul ignore next */ diff --git a/src/types.ts b/src/types.ts index eb0c342d..7c7af92f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -109,7 +109,11 @@ export type Store< S extends StateTree, G, A -> = StoreWithState & S & StoreWithGetters & StoreWithActions +> = StoreWithState & + S & + StoreWithGetters & + StoreWithActions & + PiniaCustomProperties export type GenericStore = Store< string, @@ -138,3 +142,9 @@ declare global { } } } + +/** + * Properties that are added to every store by `pinia.use()` + */ +// eslint-disable-next-line +export interface PiniaCustomProperties {}