]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
feat(types): expose DefineStoreOptions
authorEduardo San Martin Morote <posva13@gmail.com>
Thu, 8 Apr 2021 16:28:57 +0000 (18:28 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Thu, 8 Apr 2021 16:28:57 +0000 (18:28 +0200)
src/index.ts
src/store.ts
src/types.ts

index 718d9f8e57ab5f4a8342e1a8f5221f5ba964e627..af105179dcc9e95ba7559fac7282116edbbe04fa 100644 (file)
@@ -12,6 +12,7 @@ export {
   StoreWithActions,
   StoreWithState,
   PiniaCustomProperties,
+  DefineStoreOptions,
 } from './types'
 
 // TODO: remove in beta
index 792168e247b61b9aa5e9edf7c3f26c6288021f5b..ed350ea82975b3747c56613011452caf31e147a4 100644 (file)
@@ -11,6 +11,7 @@ import {
   StateDescriptor,
   Method,
   PiniaCustomProperties,
+  DefineStoreOptions,
 } from './types'
 import {
   getActivePinia,
@@ -257,20 +258,7 @@ export function defineStore<
   S extends StateTree,
   G /* extends Record<string, StoreGetterThis> */,
   A /* extends Record<string, StoreAction> */
->(options: {
-  id: Id
-  state?: () => S
-  getters?: G & ThisType<S & StoreWithGetters<G> & PiniaCustomProperties>
-  // allow actions use other actions
-  actions?: A &
-    ThisType<
-      A &
-        S &
-        StoreWithState<Id, S> &
-        StoreWithGetters<G> &
-        PiniaCustomProperties
-    >
-}) {
+>(options: DefineStoreOptions<Id, S, G, A>) {
   const { id, state, getters, actions } = options
 
   return function useStore(pinia?: Pinia | null): Store<Id, S, G, A> {
index 543f8792525f8e9b619a4f161539f602771c4b80..42a9dd51d625abc4185c42b1202ad52bc1ab1da2 100644 (file)
@@ -170,3 +170,27 @@ export interface PiniaCustomProperties<
   G = Record<string, Method>,
   A = Record<string, Method>
 > {}
+
+/**
+ * Options parameter of `defineStore()`. Can be extended to augment stores with
+ * the plugin API.
+ */
+export interface DefineStoreOptions<
+  Id extends string,
+  S extends StateTree,
+  G /* extends Record<string, StoreGetterThis> */,
+  A /* extends Record<string, StoreAction> */
+> {
+  id: Id
+  state?: () => S
+  getters?: G & ThisType<S & StoreWithGetters<G> & PiniaCustomProperties>
+  // allow actions use other actions
+  actions?: A &
+    ThisType<
+      A &
+        S &
+        StoreWithState<Id, S> &
+        StoreWithGetters<G> &
+        PiniaCustomProperties
+    >
+}