From c40c46272b6e3254dc48b7562dec3a51b55836ad Mon Sep 17 00:00:00 2001 From: yang Date: Sat, 1 Sep 2018 00:34:16 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dd.ts=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E6=94=AF=E6=8C=81tsx=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/vue.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; } } From 19025fda57b2899bd831d9643d4df74e12511ba1 Mon Sep 17 00:00:00 2001 From: yangdan Date: Wed, 2 Jun 2021 17:26:04 +0800 Subject: [PATCH 2/3] Providing generic support for actioncontext --- types/index.d.ts | 51 ++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index aeb69617f..5b877fefd 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> { + (type: T, payload?: Parameters[1], options?: DispatchOptions): Promise; +

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

>(payloadWithType: P, options?: CommitOptions): void; +} + +export interface ActionContext< + State, + RootState, + Getters extends Record = any, + Mutations extends Record = any, + Actions extends Record = any, + RootGetters = any +> { + dispatch: Dispatch; + commit: Commit; + state: State; + getters: { + [K in keyof Getters]: ReturnType; + }; + rootState: RootState; + rootGetters: RootGetters; +} + +export interface Payload { + type: keyof T; } export interface MutationPayload extends Payload { From f8cd115640bd653c6a1e9f9a32a635c5082e4036 Mon Sep 17 00:00:00 2001 From: yangdan Date: Wed, 2 Jun 2021 17:38:53 +0800 Subject: [PATCH 3/3] Correct type definition to avoid error --- types/index.d.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index 5b877fefd..3aca51fad 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -43,12 +43,12 @@ export declare class Store { export declare function install(Vue: typeof _Vue): void; -export interface Dispatch = any> { +export interface Dispatch any> = any> { (type: T, payload?: Parameters[1], options?: DispatchOptions): Promise;

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

>(payloadWithType: P, options?: CommitOptions): void; } @@ -56,9 +56,9 @@ export interface Commit = any> { export interface ActionContext< State, RootState, - Getters extends Record = any, - Mutations extends Record = any, - Actions extends Record = any, + Getters extends Record any> = any, + Mutations extends Record any> = any, + Actions extends Record any> = any, RootGetters = any > { dispatch: Dispatch; @@ -71,7 +71,7 @@ export interface ActionContext< rootGetters: RootGetters; } -export interface Payload { +export interface Payload any } = {}> { type: keyof T; }