Skip to content
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

Cannot specify a payload on a getter #1

Open
kpturner opened this issue Dec 10, 2018 · 2 comments
Open

Cannot specify a payload on a getter #1

kpturner opened this issue Dec 10, 2018 · 2 comments

Comments

@kpturner
Copy link

kpturner commented Dec 10, 2018

I tried vuex-typescript but got frustrated by the fact that I could not define a payload parameter on a getter and have it recognised by the proxied function, so I switched to this library in the hope that it was fixed but it still gives me a typescript error. This seems to work fine for actions and mutations, but not getters.

Example (assumes a module called config)

    getters: {
        getConfig(state: IConfigModuleState, path: string): any {
            return state[path];
        }
    }

^^^^ takes a path parameter

I then define

const { read } = getStoreAccessors<IConfigModuleState, IRootState>('config');
export const readConfig = read(config.getters.getConfig)

But if I try to reference that anywhere like this:

readConfig(this.$store, 'foo')

I get a typescript error: Expected 1 arguments but got 2

As I say, it seems fine for actions and mutations

What have I done wrong?

@rolandbodenstaff
Copy link

Had the exact same problem but finally found that it returns the getter itself. So you can do
readConfig(this.$store)('foo')

@joedski
Copy link

joedski commented May 24, 2019

Getters do not accept payloads, they're just Computed Props for the Store.

You can return a function from a Getter to allow some sort of querying, but keep in mind that only that created function itself is cached as a value, not the calculations that that function itself does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants