From: Eduardo San Martin Morote Date: Thu, 8 Apr 2021 16:28:57 +0000 (+0200) Subject: feat(types): expose DefineStoreOptions X-Git-Tag: v2.0.0-alpha.11~30 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=c72707070a5096df62a4bab269ce9087e2d9c102;p=thirdparty%2Fvuejs%2Fpinia.git feat(types): expose DefineStoreOptions --- diff --git a/src/index.ts b/src/index.ts index 718d9f8e..af105179 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,6 +12,7 @@ export { StoreWithActions, StoreWithState, PiniaCustomProperties, + DefineStoreOptions, } from './types' // TODO: remove in beta diff --git a/src/store.ts b/src/store.ts index 792168e2..ed350ea8 100644 --- a/src/store.ts +++ b/src/store.ts @@ -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 */, A /* extends Record */ ->(options: { - id: Id - state?: () => S - getters?: G & ThisType & PiniaCustomProperties> - // allow actions use other actions - actions?: A & - ThisType< - A & - S & - StoreWithState & - StoreWithGetters & - PiniaCustomProperties - > -}) { +>(options: DefineStoreOptions) { const { id, state, getters, actions } = options return function useStore(pinia?: Pinia | null): Store { diff --git a/src/types.ts b/src/types.ts index 543f8792..42a9dd51 100644 --- a/src/types.ts +++ b/src/types.ts @@ -170,3 +170,27 @@ export interface PiniaCustomProperties< G = Record, A = Record > {} + +/** + * 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 */, + A /* extends Record */ +> { + id: Id + state?: () => S + getters?: G & ThisType & PiniaCustomProperties> + // allow actions use other actions + actions?: A & + ThisType< + A & + S & + StoreWithState & + StoreWithGetters & + PiniaCustomProperties + > +}