Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 30 additions & 21 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,36 @@ export declare class Store<S> {

export declare function install(Vue: typeof _Vue): void;

export interface Dispatch {
(type: string, payload?: any, options?: DispatchOptions): Promise<any>;
<P extends Payload>(payloadWithType: P, options?: DispatchOptions): Promise<any>;
}

export interface Commit {
(type: string, payload?: any, options?: CommitOptions): void;
<P extends Payload>(payloadWithType: P, options?: CommitOptions): void;
}

export interface ActionContext<S, R> {
dispatch: Dispatch;
commit: Commit;
state: S;
getters: any;
rootState: R;
rootGetters: any;
}

export interface Payload {
type: string;
export interface Dispatch<Actions extends Record<string, (...args: any) => any> = any> {
<T extends keyof Actions>(type: T, payload?: Parameters<Actions[T]>[1], options?: DispatchOptions): Promise<any>;
<P extends Payload<Actions>>(payloadWithType: P, options?: DispatchOptions): Promise<any>;
}

export interface Commit<Mutations extends Record<string, (...args: any) => any> = any> {
<T extends keyof Mutations>(type: T, payload?: Parameters<Mutations[T]>[1], options?: CommitOptions): void;
<P extends Payload<Mutations>>(payloadWithType: P, options?: CommitOptions): void;
}

export interface ActionContext<
State,
RootState,
Getters extends Record<string, (...args: any) => any> = any,
Mutations extends Record<string, (...args: any) => any> = any,
Actions extends Record<string, (...args: any) => any> = any,
RootGetters = any
> {
dispatch: Dispatch<Actions>;
commit: Commit<Mutations>;
state: State;
getters: {
[K in keyof Getters]: ReturnType<Getters[K]>;
};
rootState: RootState;
rootGetters: RootGetters;
}

export interface Payload<T extends { [key: string]: (...args: any) => any } = {}> {
type: keyof T;
}

export interface MutationPayload extends Payload {
Expand Down
2 changes: 1 addition & 1 deletion types/vue.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ declare module "vue/types/options" {

declare module "vue/types/vue" {
interface Vue {
$store: Store<any>;
$store?: Store<any>;
}
}