From 5ef71407764384bef13a4f46fd001beade387d24 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Tue, 27 Apr 2021 10:46:52 +0200 Subject: [PATCH] feat(plugins): allow void return --- src/index.ts | 3 +++ src/rootStore.ts | 5 ++++- test-dts/plugins.test-d.ts | 26 ++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 test-dts/plugins.test-d.ts diff --git a/src/index.ts b/src/index.ts index 101dc7d4..39289f6e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,6 +8,9 @@ export { defineStore } from './store' export { StateTree, Store, + GenericStore, + GenericStoreDefinition, + StoreDefinition, StoreWithGetters, StoreWithActions, StoreWithState, diff --git a/src/rootStore.ts b/src/rootStore.ts index a5874343..811b2002 100644 --- a/src/rootStore.ts +++ b/src/rootStore.ts @@ -60,7 +60,10 @@ export const getClientApp = () => clientApp * Plugin to extend every store */ export interface PiniaStorePlugin { - (context: { app: App; store: GenericStore }): Partial + (context: { + app: App + store: GenericStore + }): Partial | void } /** diff --git a/test-dts/plugins.test-d.ts b/test-dts/plugins.test-d.ts new file mode 100644 index 00000000..c1d542e2 --- /dev/null +++ b/test-dts/plugins.test-d.ts @@ -0,0 +1,26 @@ +import { + defineStore, + expectType, + mapStores, + createPinia, + GenericStore, +} from '.' + +const useCounter = defineStore({ + id: 'counter', + state: () => ({ n: 0 }), +}) + +type CounterStore = ReturnType + +const computedStores = mapStores(useCounter) + +expectType<{ + counterStore: () => CounterStore +}>(computedStores) + +const pinia = createPinia() + +pinia.use(({ store }) => { + expectType(store) +}) -- 2.47.2