import type { Dictionary } from '@empathyco/x-utils'; import type { ActionContext } from 'vuex'; import type { PropsWithType } from '../utils'; import type { MutationsDictionary } from './mutations.types'; import type { AnyXStoreModule, ExtractPayload, RootXStoreState } from './store.types'; /** * Type safe Vuex {@link https://vuex.vuejs.org/api/#actions | Action} context, with the local * types of the module. * * @param State - The module state dictionary type definition. * @param Getters - The module getters dictionary type definition. * @param Mutations - The module mutation dictionary type definition. * @param Actions - The module actions dictionary type definition. * @public */ export interface XActionContext, Actions extends ActionsDictionary> extends ActionContext { getters: Getters; commit: ( void>>(mutation: MutationName) => void) & ((mutation: MutationName, payload: ExtractPayload) => void); dispatch: ( any>>(action: ActionName) => ExtractActionReturn) & ((action: ActionName, payload: ExtractPayload) => ExtractActionReturn); } /** * Flattens the (probably) chained promises of an action type. * * @param Action - The action function to extract its type. * @public */ export type ExtractActionReturn any> = ReturnType extends Promise ? ReturnType : Promise>; /** * Util type for being used on generic constraints which will only accept an object containing * actions. * * @example Example constraint * ```typescript * // This function allows receiving any object who only contains actions; * function sampleFunction\\>(actions: Actions): void; * ``` * @public */ export type ActionsDictionary = Record any>; /** * Type-safe actions definition type. An object with this type is what it is needed to define * {@link https://vuex.vuejs.org/ | Vuex} actions. * * @param State - The module state dictionary type definition. * @param Getters - The module getters dictionary type definition. * @param Mutations - The module mutation dictionary type definition. * @param Actions - The module actions dictionary type definition. * * @public */ export type ActionsTree, Actions extends ActionsDictionary> = { [Key in keyof Actions]: (context: XActionContext, payload: ExtractPayload) => ReturnType | Promise>; }; /** * Alias for any actions tree. Use only when you really don't care about the actions type. * * @public */ export type AnyActionsTree = ActionsTree, ActionsDictionary>; /** * Type for implementing actions for a module with a class. * * @param Module - The module this actions belong to. * @public */ export type ActionsClass = Partial; //# sourceMappingURL=actions.types.d.ts.map