vuejs / vetur

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

Vetur not inferring types correctly, thinks computed property is a vuex `MutationMethod` #1346

Closed shailen-naidoo closed 5 years ago

shailen-naidoo commented 5 years ago

Info

Problem

I am getting this weird error I am using mapState to bind customItems property to my component from vuex. I am spreading mapState into the computed property. When i use customItems anywhere in the component, Vetur thinks that customItems is of type MutationMethod

Here is the component: image

Here is the error: image

Reproducible Case

  1. Create a Vue component
  2. use mapState to bind a property from Vuex to the component
  3. Try to use that property elsewhere in the component
  4. You should get an error
ktsn commented 5 years ago

This is because return type of mapXXX is just a record type. You need to cast it by yourself currently.

...mapMutation({
  addCustomItem: 'form/ADD_CUSTOM_ITEM'
}) as {
  addCustomItem: (payload: any) => void
}

Closing as this is Vuex problem rather than Vetur.

shailen-naidoo commented 5 years ago

Thanks

On Tue, 30 Jul 2019, 08:11 katashin, notifications@github.com wrote:

Closed #1346 https://github.com/vuejs/vetur/issues/1346.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/vuejs/vetur/issues/1346?email_source=notifications&email_token=AGKSRXEOJJZCH24FNPZS7RLQB7LRDA5CNFSM4H46QXJKYY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOSYPSSGY#event-2518624539, or mute the thread https://github.com/notifications/unsubscribe-auth/AGKSRXHOASZYHG2PAGOP4HLQB7LRDANCNFSM4H46QXJA .