Method,
PiniaCustomProperties,
DefineStoreOptions,
+ StoreDefinition,
} from './types'
import {
getActivePinia,
S extends StateTree,
G /* extends Record<string, StoreGetterThis> */,
A /* extends Record<string, StoreAction> */
->(options: DefineStoreOptions<Id, S, G, A>) {
+>(options: DefineStoreOptions<Id, S, G, A>): StoreDefinition<Id, S, G, A> {
const { id, state, getters, actions } = options
- return function useStore(pinia?: Pinia | null): Store<Id, S, G, A> {
+ function useStore(pinia?: Pinia | null): Store<Id, S, G, A> {
// avoid injecting if `useStore` when not possible
pinia = pinia || (getCurrentInstance() && inject(piniaSymbol))
if (pinia) setActivePinia(pinia)
actions as Record<string, Method> | undefined
)
}
+
+ // used by devtools
+ useStore.$id = id
+
+ return useStore
}
PiniaCustomProperties<Id, S, G, A>
/**
- * Generic store type
+ * Return type of `defineStore()`. Function that allows instantiating a store.
+ */
+export interface StoreDefinition<
+ Id extends string,
+ S extends StateTree,
+ G /* extends Record<string, StoreGetterThis> */,
+ A /* extends Record<string, StoreAction> */
+> {
+ (pinia?: Pinia | null | undefined): Store<Id, S, G, A>
+ $id: Id
+}
+
+/**
+ * Generic version of Store
*/
export type GenericStore = Store<
string,
Record<string, Method>
>
+/**
+ * Generic version of `StoreDefinition`
+ */
+export interface GenericStoreDefinition {
+ (pinia?: Pinia | null | undefined): Store<
+ string,
+ StateTree,
+ Record<string, Method>,
+ Record<string, Method>
+ >
+ $id: string
+}
+
/**
* Properties that are added to every store by `pinia.use()`
*/