diff --git a/types/index.d.ts b/types/index.d.ts index aeb69617f..3aca51fad 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -43,27 +43,36 @@ export declare class Store { export declare function install(Vue: typeof _Vue): void; -export interface Dispatch { - (type: string, payload?: any, options?: DispatchOptions): Promise; -

(payloadWithType: P, options?: DispatchOptions): Promise; -} - -export interface Commit { - (type: string, payload?: any, options?: CommitOptions): void; -

(payloadWithType: P, options?: CommitOptions): void; -} - -export interface ActionContext { - dispatch: Dispatch; - commit: Commit; - state: S; - getters: any; - rootState: R; - rootGetters: any; -} - -export interface Payload { - type: string; +export interface Dispatch any> = any> { + (type: T, payload?: Parameters[1], options?: DispatchOptions): Promise; +

>(payloadWithType: P, options?: DispatchOptions): Promise; +} + +export interface Commit any> = any> { + (type: T, payload?: Parameters[1], options?: CommitOptions): void; +

>(payloadWithType: P, options?: CommitOptions): void; +} + +export interface ActionContext< + State, + RootState, + Getters extends Record any> = any, + Mutations extends Record any> = any, + Actions extends Record any> = any, + RootGetters = any +> { + dispatch: Dispatch; + commit: Commit; + state: State; + getters: { + [K in keyof Getters]: ReturnType; + }; + rootState: RootState; + rootGetters: RootGetters; +} + +export interface Payload any } = {}> { + type: keyof T; } export interface MutationPayload extends Payload { diff --git a/types/vue.d.ts b/types/vue.d.ts index 302fc4eb6..d6cf34d4c 100644 --- a/types/vue.d.ts +++ b/types/vue.d.ts @@ -13,6 +13,6 @@ declare module "vue/types/options" { declare module "vue/types/vue" { interface Vue { - $store: Store; + $store?: Store; } }