You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The helper mapActions seems to suffer from the same problem as the problem described with mapState and mapGetters. I'm betting that the solution described there also works for mapActions, but I'm not exactly sure what form it should take.
For instance, marking the action as any will silence the error, but I feel like there's a more correct type for actions. It might be good to have an example of the right type for actions.
import Vue, {VueConstructor} from 'vue';
import {mapActions} from 'vuex';
// Without this interface you get the following error
// 19:26 Property 'myAction' does not exist on type 'CombinedVueInstance<Vue, unknown, { doIt(): void; }, unknown, Readonly<Record<never, any>>>'.
interface VuexBindings {
myAction: any;
}
export default (Vue as VueConstructor<Vue & VuexBindings>).extend({
created() {
console.log(this.myAction);
},
methods: {
doIt() {
console.log("doing a thing");
},...mapActions(['myAction'])
},
});
Though it's a bummer to have to spell out that function type in every .vue file you want to use it in. You could export your function and do it this way:
vuex has next to no typescript support, its a real pain.
I have on my most recent project, cannibalized this pr from kstn vuejs/vuex#1121
There's a bit of work to make it compile in newer ts versions and I modified it from there to make it work better for the class style syntax.
Ill try clean it up and post a gist here in the weekend but if you want results now you can try hack away at it
The helper
mapActions
seems to suffer from the same problem as the problem described withmapState
andmapGetters
. I'm betting that the solution described there also works formapActions
, but I'm not exactly sure what form it should take.For instance, marking the action as
any
will silence the error, but I feel like there's a more correct type for actions. It might be good to have an example of the right type for actions.The text was updated successfully, but these errors were encountered: