Plugins: Expose `DefineStoreOptionsBase` in `PiniaCustomProperties`
Author: b-straussCreated Apr 22, 2022Updated Aug 14, 2026
Labelsfeature requesttypescript
What problem is this solving
I wrote a plugin to solve #625. This is basically working, but the types of the stores defined in the new stores option in DefineStoreOptionsBase are not accessible inside PiniaCustomProperties.
import type {PiniaPluginContext, Store, StoreDefinition} from 'pinia';
declare module 'pinia' {
export interface DefineStoreOptionsBase<S, Store> {
stores?: Record<string, StoreDefinition>;
}
export interface PiniaCustomProperties<Id, S, G, A> {
readonly stores: Readonly<Record<string, Store>>;
}
}
export function piniaPluginStores (context: PiniaPluginContext) {
return {
get stores () {
return Object.freeze(
Object.entries(context.options.stores ?? {})
.reduce<Record<string, Store>>((accumulator, [name, definition]) => {
accumulator[name] = definition();
return accumulator;
}, {}),
);
},
};
}Proposed solution
If the store options would be accessible inside PiniaCustomProperties, the actual types of the concrete stores could be accessed with this.stores.
Describe alternatives you've considered
No response
Source: vuejs/pinia