Skip to content

mapActions: property does not exist on type #2

Closed
@amoe

Description

@amoe

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'])
    },
});
export default new Vuex.Store({
    state: {
    },
    mutations: {
    },
    actions: {
        myAction(store) {
            console.log("doing action");
        }
    },
    modules: {
    },
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions