Cannot specify a payload on a getter
kpturner opened this issue · comments
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?
Had the exact same problem but finally found that it returns the getter itself. So you can do
readConfig(this.$store)('foo')
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.