vuejs / vetur

Vue tooling for VS Code.
https://vuejs.github.io/vetur/
MIT License
5.75k stars 593 forks source link

Mutation not recognized when imported with mapMutations next to other methods #2592

Open ntraut opened 3 years ago

ntraut commented 3 years ago

Info

Problem

I try to import a mutation with the method ...mapMutations. If this is the only method in my vue file can use it without any warning. I have this in my script section:

  methods: {
    ...mapMutations(['increment'])
  }

and this in my template section:

<button @click="increment">X</button>

But if I add another method which is independent from my initial method:

  methods: {
    method2() {
      console.log('method2')
    },
    ...mapMutations(['increment'])
  }

I get the following error in my template:

Property 'increment' does not exist on type 'CombinedVueInstance<{ method2(): void; } & Record<never, any> & Vue, object, object, object, Record<never, any>>'.

The vue app is still working, I only get the error in vscode.

Reproducible Case

I did a minimal example starting from vue hello world: https://github.com/ntraut/vue-hello-world

yoyo930021 commented 3 years ago

It's a type limit in Vuex.

Ref: https://github.com/vuejs/vuex/issues/1417 https://github.com/vuejs/vuex/pull/1121

yoyo930021 commented 3 years ago

Temporarily open issue to confirm.

ntraut commented 3 years ago

This problem is too complicated for I can understand it fully but what seems strange to me is that if there is only ...mapMutations we don't get any warning: even if we type the wrong name, vs code tells increment0 is a mutation method. But if we add another method with no link we get the warning.

In my opinion the warning should occur either in both cases or none of them...