0

Trying to upgrade a project that is a couple of years old that uses vuex as store to the latest version of Vue3 with Vite and Typescript.

Now stuck on an issue with getters calling other getters. This used to work and I managed to get it to compile without issues but I am now getting an error when upgrading.

"TypeError: Cannot read properties of undefined (reading 'GET_POSITION_ISSUE')"

[GET_MERGED_ISSUES]: (state, getters) => (position) => {
    ...
    let positionIssue = getters[GET_POSITION_ISSUE](position)
    ...
  }

It compiles after setting :any on the parameters, but gives runtime error.

A complete rewrite using Pinia is in the works, but I would prefer not to redo it all at once but transferring functionality piece by piece instead.

Any help would be appreciated!

1
  • "project that is a couple of years old that uses vuex as store to the latest version of Vue3" - from which to which versions? Notice that vuex hasn't been updated for several years. Please, provide stackoverflow.com/help/mcve for your problem. Nothing changed in this regard iirc Commented Aug 22 at 13:15

2 Answers 2

1

After some more research I found a way to access the getter by importing the store and going that way. Maybe not the correct way but it will do until we move to Pinia.

import { store } from '../..'

[GET_MERGED_ISSUES]: (state) => (position) => {
    ...
    let positionIssue = store.getters[GET_POSITION_ISSUE](position)
    ...
  }
Sign up to request clarification or add additional context in comments.

Comments

0

Vue 3 allows getters to reference each other via this.getters, Try this code:

[GET_MERGED_ISSUES](state, getters) {
  return (position: number) => {
    const positionIssue = this.getters[GET_POSITION_ISSUE](position)
    return positionIssue 
  }
}

1 Comment

This did not work for me at least. Found another way though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.