-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add type annotation for the context of actions and mutations #1322
Conversation
ping @ktsn |
types/index.d.ts
Outdated
export interface ActionObject<S, R> { | ||
root?: boolean; | ||
handler: ActionHandler<S, R>; | ||
} | ||
|
||
export type Getter<S, R> = (state: S, getters: any, rootState: R, rootGetters: any) => any; | ||
export type Action<S, R> = ActionHandler<S, R> | ActionObject<S, R>; | ||
export type Mutation<S> = (state: S, payload: any) => any; | ||
export type Mutation<S> = (this: Store<S>, state: S, payload: any) => any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the use case of this
in mutations?
I think we should not use that in mutations while it might be useful in actions.
I think so too. I just followed the implementation. |
@sue71 If there are no use case for mutations, can we remove |
@ktsn make sense. I'll do so. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The handlers for actions and mutations are bound to the store, but there is no type annotation for this behavior.
This PR will enable us to use
this
as Store in the handlers.