Skip to content

Vuex/Typescript mappers issue: property does not exist on type 'CombinedVueInstance<Vue, ...>' #1220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mzymta opened this issue Apr 9, 2018 · 22 comments
Labels
duplicate This issue or pull request already exists

Comments

@mzymta
Copy link

mzymta commented Apr 9, 2018

Version

3.0.1

Reproduction link

https://github.com/mzymta/vuex-mappers-issue

Steps to reproduce

Add mapped methods using mapMutations, mapActions, create another component method that uses any of the mapped methods. Build fails with error:

Error: Property NAME_OF_MAPPED_METHOD does not exist on type 'CombinedVueInstance<Vue, ...>'

The below code works fine if there is no methodThatUsesActionOrMutation() method.
With methodThatUsesActionOrMutation() method build fails with error:

TS2339: Property 'pushStringArray' does not exist on type 'CombinedVueInstance<Vue, {}, { methodThatUsesActionOrMutation(): void; }, { newStr: any; getLongS...'.

import Vue from 'vue';
import {mapActions, mapGetters, mapMutations} from 'vuex'

export default Vue.extend({
  computed: {
    ...mapGetters({
      getStringsArray: 'getStringsArray'
    }),
    newStr: {
      get(): string {
        return this.$store.state.newStr;
      },
      set(value: string) {
        this.$store.commit('setNewStr', value);
      }
    }
  },
  methods: {
    ...mapMutations({
      pushStringArray: 'pushStringArray'
    }),
    ...mapActions({
      pushStringArrayAsync: 'pushStringArrayAsync'
    }),
    methodThatUsesActionOrMutation() {
      // HERE COMES THE ERROR
      this.pushStringArray();
      console.log('done');
    }
  }
}

What is expected?

mapped method pushStringArray() can be used in other component methods - build doesn't fail

What is actually happening?

Build fails with error:
TS2339: Property 'pushStringArray' does not exist on type 'CombinedVueInstance<Vue, {}, { methodThatUsesActionOrMutation(): void; }, { newStr: any; }, Reado...'.

@ktsn
Copy link
Member

ktsn commented Apr 10, 2018

Duplicate of #1119
Fix is going on #1121

@ktsn ktsn closed this as completed Apr 10, 2018
@ktsn ktsn added the duplicate This issue or pull request already exists label Apr 10, 2018
@sknightq
Copy link

I donot know yet~ And I have got a seem problem, but not Typescript, just a normal Vuex project with vscode, the red errors only appear in template tags...

Me too!

@pikax
Copy link
Member

pikax commented Apr 25, 2019

@JWong1105 vscode uses the typescript typings from the dependencies when using javascript

@1316636084
Copy link

how to fix it

@lihaowu
Copy link

lihaowu commented Apr 26, 2019

昨天VSCode大批量更新,去掉报错的办法,File->Proferences->Extensions->Vetur->Validation:Template , Cancel it.

@Aslantoe
Copy link

reload一下Vetur好了

@floait
Copy link

floait commented Apr 29, 2019

reload the plugin Vetur, opening the new world!!!!!!

@satouriko
Copy link

Any update here? I've facing the same issue.

@DanielRuf
Copy link

We still face this issue, even with the latest version / release.

@DanielRuf
Copy link

We use mapGetters.

@xesjkeee
Copy link

xesjkeee commented Mar 9, 2020

I still face this issue using mapMutations

@SanyaShevchuk
Copy link

SanyaShevchuk commented Mar 11, 2020

still face this problem with mapState, mapMutations etc. It can be reproduced if we have our component's computed/methods and vuex such as:

computed: {
  myProperty() {
     return true
  },
  ...mapState('someModule', ['someStateField'])
}

@kiaking
Copy link
Member

kiaking commented Mar 12, 2020

@SanyaShevchuk Could you try annotating the other properties? (Computed methods require return value annotation).

computed: {
  myProperty(): boolean { // <- Here
     return true
  },
  ...mapState('someModule', ['someStateField'])
}

@pablo-iwg
Copy link

The above fixed the issue for me. @kiaking thank you!

@SanyaShevchuk
Copy link

yes I tried, it works for mapState and mapGetters, but does not for mapMutations. Ive added return type to methods as u did for computed, but still get an error

@SanyaShevchuk
Copy link

@pablo-iwg did u have a case with mutations or only computed?

@pablo-iwg
Copy link

I was using getters within a computed property and forgot to annotate the property. I was not using mutations.

@SanyaShevchuk
Copy link

SanyaShevchuk commented Apr 23, 2020

Ive added types for everything but method from mapMutations still gets me error

export default Vue.extend({
  name: 'LogInPage',
  data() {
    return {
      loading: false as boolean,
      loginErrors: {} as ILoginErrors,
      email: '' as string,
      password: '' as string,
    };
  },
  computed: {
    errorMessage(): string {
      return 'errorMessage';
    },
  },
  mounted(): void {
    this.resetState();
  },
  methods: {
    ...mapMutations('someModule', ['resetState']),
    async onSignIn(): Promise<any> {
      this.loading = true;
      this.loginErrors = {};

      try {
        await signIn({
          username: this.email,
          password: this.password,
        });
      } catch (e) {
        console.log(e)
      } finally {
        this.loading = false;
      }
    },
    hasError(): boolean {
      return true;
    },
  },
});

@jQrgen
Copy link

jQrgen commented May 9, 2020

+1

@Smilebags
Copy link

I'm also only experiencing this with mapMutations, all getters and method return values are typed.

@blaskovicz
Copy link

Is there currently an open issue for this? I'm still seeing this for ...mapState()

@fbnlsr
Copy link

fbnlsr commented Jun 29, 2023

Just chiming in that I also get this issue, but only when mapState() is present alongside others methods:

computed: {
      ...mapState(['user']),
      acquereurName(): string {
        return this.item.acquereur?.formName ?? ''
      },
    },

Here I get Property 'user' does not exist on type 'Property 'user' does not exist on type 'CombinedVueInstance<Vue, { minPosition: number; busy: boolean; itemData: RequisitionItem; rubriques: never[]; stockStatuses: { label: string; value: string; color: string; textColor: string; }[]; ... 30 more ...; showRegroupModal: boolean; }, { ...; }, { ...; }, Readonly<...>>'.Vetur(2339)

But if my component only has this:

computed: {
     ...mapState(['user']),
  },

...then there are no errors to report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests