StateDescriptor,
GenericStore,
PiniaCustomProperties,
+ Method,
+ DefineStoreOptions,
+ Store,
} from './types'
/**
/**
* Context argument passed to Pinia plugins.
*/
-export interface PiniaPluginContext {
+export interface PiniaPluginContext<
+ Id extends string = string,
+ S extends StateTree = StateTree,
+ G = Record<string, Method>,
+ A = Record<string, Method>
+> {
/**
* pinia instance.
*/
-
pinia: Pinia
+
/**
* Current app created with `Vue.createApp()`.
*/
/**
* Current store being extended.
*/
- store: GenericStore
+ store: Store<Id, S, G, A>
+
+ /**
+ * Current store being extended.
+ */
+ options: DefineStoreOptions<Id, S, G, A>
}
/**
descriptor: StateDescriptor<S>,
$id: Id,
getters: G = {} as G,
- actions: A = {} as A
+ actions: A = {} as A,
+ options: DefineStoreOptions<Id, S, G, A>
) {
const pinia = getActivePinia()
// apply all plugins
pinia._p.forEach((extender) => {
- Object.assign(store, extender({ store, app: pinia._a, pinia }))
+ Object.assign(store, extender({ store, app: pinia._a, pinia, options }))
})
return store
export function defineStore<
Id extends string,
S extends StateTree,
- G /* extends Record<string, StoreGetterThis> */,
- A /* extends Record<string, StoreAction> */
+ // the omission of the extends is necessary for type inference
+ G /* extends Record<string, Method> */,
+ A /* extends Record<string, Method> */
>(options: DefineStoreOptions<Id, S, G, A>): StoreDefinition<Id, S, G, A> {
const { id, state, getters, actions } = options
storeAndDescriptor[1],
id,
getters as Record<string, Method> | undefined,
- actions as Record<string, Method> | undefined
+ actions as Record<string, Method> | undefined,
+ // @ts-ignore: because we don't have extend on G and A
+ options
)
if (
storeAndDescriptor[1],
id,
getters as Record<string, Method> | undefined,
- actions as Record<string, Method> | undefined
+ actions as Record<string, Method> | undefined,
+ // @ts-ignore: because we don't have extend on G and A
+ options
)
}