diff --git a/types/index.d.ts b/types/index.d.ts index 585b7d6b0..db56861f1 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -28,7 +28,7 @@ export declare class Store { hotUpdate(options: { actions?: ActionTree; - mutations?: MutationTree; + mutations?: MutationTree; getters?: GetterTree; modules?: ModuleTree; }): void; @@ -48,6 +48,7 @@ export interface Commit { export interface ActionContext { dispatch: Dispatch; + commit: Commit; state: S; getters: any; @@ -80,13 +81,13 @@ export interface StoreOptions { state?: S; getters?: GetterTree; actions?: ActionTree; - mutations?: MutationTree; + mutations?: MutationTree; modules?: ModuleTree; plugins?: Plugin[]; strict?: boolean; } -export type ActionHandler = (injectee: ActionContext, payload: any) => any; +export type ActionHandler = (this: Store, injectee: ActionContext, payload: any) => any; export interface ActionObject { root?: boolean; handler: ActionHandler; @@ -94,7 +95,7 @@ export interface ActionObject { export type Getter = (state: S, getters: any, rootState: R, rootGetters: any) => any; export type Action = ActionHandler | ActionObject; -export type Mutation = (state: S, payload: any) => any; +export type Mutation = (this: Store, state: S, payload: any) => any; export type Plugin = (store: Store) => any; export interface Module { @@ -102,7 +103,7 @@ export interface Module { state?: S | (() => S); getters?: GetterTree; actions?: ActionTree; - mutations?: MutationTree; + mutations?: MutationTree; modules?: ModuleTree; } @@ -118,8 +119,8 @@ export interface ActionTree { [key: string]: Action; } -export interface MutationTree { - [key: string]: Mutation; +export interface MutationTree { + [key: string]: Mutation; } export interface ModuleTree { @@ -129,5 +130,5 @@ export interface ModuleTree { declare const _default: { Store: typeof Store; install: typeof install; -} +}; export default _default; diff --git a/types/test/index.ts b/types/test/index.ts index 0253e5df8..68469bf6d 100644 --- a/types/test/index.ts +++ b/types/test/index.ts @@ -59,6 +59,7 @@ namespace RootModule { }, actions: { foo ({ state, getters, dispatch, commit }, payload) { + this.state.value; state.value; getters.count; dispatch("bar", {}); @@ -66,7 +67,9 @@ namespace RootModule { } }, mutations: { - bar (state, payload) {} + bar (state, payload) { + this.state.value; + } }, strict: true }); @@ -83,6 +86,7 @@ namespace RootDefaultModule { }, actions: { foo ({ state, getters, dispatch, commit }, payload) { + this.state.value; state.value; getters.count; dispatch("bar", {}); @@ -90,7 +94,9 @@ namespace RootDefaultModule { } }, mutations: { - bar (state, payload) {} + bar (state, payload) { + this.state.value; + } }, strict: true }); @@ -107,7 +113,10 @@ namespace NestedModules { }; d: { value: number; - }; + }, + e: { + value: number; + } }; } @@ -145,7 +154,22 @@ namespace NestedModules { b: { modules: { c: module, - d: module + d: module, + e: { + state: { + value: 0 + }, + actions: { + foo(context: ActionStore, payload) { + this.state.a; + } + }, + mutations: { + bar(state, payload) { + this.state.b.e; + } + } + } } } }