]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
feat(plugins): allow void return
authorEduardo San Martin Morote <posva13@gmail.com>
Tue, 27 Apr 2021 08:46:52 +0000 (10:46 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Tue, 27 Apr 2021 08:46:52 +0000 (10:46 +0200)
src/index.ts
src/rootStore.ts
test-dts/plugins.test-d.ts [new file with mode: 0644]

index 101dc7d4bb6a4a23a6f4d4f9c669bd1e50653ff1..39289f6e129abcef62733b813dc224da6a1c69fe 100644 (file)
@@ -8,6 +8,9 @@ export { defineStore } from './store'
 export {
   StateTree,
   Store,
+  GenericStore,
+  GenericStoreDefinition,
+  StoreDefinition,
   StoreWithGetters,
   StoreWithActions,
   StoreWithState,
index a58743438d670d22282fa13d4b2431e787103a48..811b20029e7d88d2a17dc3486af900dd7f9e8bf5 100644 (file)
@@ -60,7 +60,10 @@ export const getClientApp = () => clientApp
  * Plugin to extend every store
  */
 export interface PiniaStorePlugin {
-  (context: { app: App; store: GenericStore }): Partial<PiniaCustomProperties>
+  (context: {
+    app: App
+    store: GenericStore
+  }): Partial<PiniaCustomProperties> | void
 }
 
 /**
diff --git a/test-dts/plugins.test-d.ts b/test-dts/plugins.test-d.ts
new file mode 100644 (file)
index 0000000..c1d542e
--- /dev/null
@@ -0,0 +1,26 @@
+import {
+  defineStore,
+  expectType,
+  mapStores,
+  createPinia,
+  GenericStore,
+} from '.'
+
+const useCounter = defineStore({
+  id: 'counter',
+  state: () => ({ n: 0 }),
+})
+
+type CounterStore = ReturnType<typeof useCounter>
+
+const computedStores = mapStores(useCounter)
+
+expectType<{
+  counterStore: () => CounterStore
+}>(computedStores)
+
+const pinia = createPinia()
+
+pinia.use(({ store }) => {
+  expectType<GenericStore>(store)
+})