vue3-task-manager icon indicating copy to clipboard operation
vue3-task-manager copied to clipboard

[Question] - Action Typing and Payloads

Open gabrielthomasjacobs opened this issue 3 years ago • 0 comments

I was reading your article (great, btw!) and following along. I noticed that you specify the type as ActionTree<State, State> & Actions.

But if you wanted to do an action with a payload, such as a login function similar to: async [ActionTypes.Login]({ commit }, {username, password}) { AuthService.login(username, password).subscribe(res => { commit(MutationType.SetUsername, res.username); commit(MutationType.SetIsLoggedIn, true); }) }

You would recieve an error because the payload {username, password} was unexpected. Removing the & Actions stops the error.

I'm still pretty new to Vuex (and fully appreciating strong typing), am I approaching this incorrectly?

gabrielthomasjacobs avatar May 11 '21 23:05 gabrielthomasjacobs