Skip to content

Commit

Permalink
fix(types): add type annotation for the context of actions (#1322)
Browse files Browse the repository at this point in the history
* feat(types): add type annotation for the context of actions and mutations

* fix(types): remove this annotation from mutations
  • Loading branch information
sue71 authored and ktsn committed Jul 18, 2018
1 parent 7eeeca0 commit d1b5c66
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export interface StoreOptions<S> {
strict?: boolean;
}

export type ActionHandler<S, R> = (injectee: ActionContext<S, R>, payload: any) => any;
export type ActionHandler<S, R> = (this: Store<R>, injectee: ActionContext<S, R>, payload: any) => any;
export interface ActionObject<S, R> {
root?: boolean;
handler: ActionHandler<S, R>;
Expand Down Expand Up @@ -129,5 +129,5 @@ export interface ModuleTree<R> {
declare const _default: {
Store: typeof Store;
install: typeof install;
}
};
export default _default;
19 changes: 17 additions & 2 deletions types/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace RootModule {
},
actions: {
foo ({ state, getters, dispatch, commit }, payload) {
this.state.value;
state.value;
getters.count;
dispatch("bar", {});
Expand All @@ -83,6 +84,7 @@ namespace RootDefaultModule {
},
actions: {
foo ({ state, getters, dispatch, commit }, payload) {
this.state.value;
state.value;
getters.count;
dispatch("bar", {});
Expand All @@ -107,7 +109,10 @@ namespace NestedModules {
};
d: {
value: number;
};
},
e: {
value: number;
}
};
}

Expand Down Expand Up @@ -145,7 +150,17 @@ namespace NestedModules {
b: {
modules: {
c: module,
d: module
d: module,
e: {
state: {
value: 0
},
actions: {
foo(context: ActionStore, payload) {
this.state.a;
}
}
}
}
}
}
Expand Down

0 comments on commit d1b5c66

Please sign in to comment.