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

GetterHandler type missing parameters? #11

Open
zerosym opened this issue Dec 28, 2017 · 6 comments
Open

GetterHandler type missing parameters? #11

zerosym opened this issue Dec 28, 2017 · 6 comments

Comments

@zerosym
Copy link

zerosym commented Dec 28, 2017

I've been trying out this approach but ran into an issue with specifying a vuex getter with more than just the state; i.e. (state, getters, rootState, rootGetters).

Shouldn't the following be GetterHandler<state: TModuleState, getters: any, rootState: TRootState, rootGetters: any) instead? I just started using Typescript so I don't know if I'm missing something.
https://github.com/istrib/vuex-typescript/blob/master/src/index.ts#L12

@skateborden
Copy link

Were you able to get this to work?

@d1820
Copy link

d1820 commented May 16, 2018

I also am trying to get this to work.. seems even the defined signature does not work correctly, RootState is also not injected into the read..

@skateborden
Copy link

I'm trying to remember the exact context of this, but I found a workaround for accessing the root state from within a module that might be helpful to others. In my index.ts I export my root vue instance export const vueApp = new Vue({ ... and then in the vuex module you can import { vueApp } and then call the static functions of another module by passing them vueApp.$store. It doesn't feel ideal but it works.

@d1820
Copy link

d1820 commented May 16, 2018

OK after some digging its a bug in Vuex-Typescript, but you can get around the issue by doing this

get currentLanguage(): string | undefined {
// this._storeFront.getters.currentLanguage points to private method below
        return read(this._storeFront.getters.currentLanguage).call(this, this.store);
    }

...

private _getCurrentLanguage(...args: any[]): string | undefined {
        const state = args[0];
        const rootState: IRootState = args[1];
        const rootStore: any = args[2];
        const rootGetters: any = args[3];
        console.log('rootGetters', rootGetters);
        ...
    }

basically Vuex-Typescript does not pass all the params and the interface they have defined is not what vuex supports, but under the covers its still vuex and that still passes the parameters correctly. The above passed Typescript checking and stuff.

@jackkoppa
Copy link

@d1820, @skateborden - I know you've likely moved on from this issue. But could you check out #22 to see if you agree with the solution? I didn't realize that the bug I was trying to fix had already been documented here 😀

jackkoppa added a commit to politico/typesafe-vuex that referenced this issue Nov 5, 2018
Copy of PR on vuex-typescript:
istrib/vuex-typescript#22
Fixes bug that did not allow users to access RootState from typed getters
Bug on vuex-typescript:
istrib/vuex-typescript#11
@jackkoppa
Copy link

jackkoppa commented Nov 5, 2018

Hi all - I realize very few people are likely going to be coming across this, but since this repo hasn't been updated since 11/13/17, I decided to fork & publish a maintained version. You can find that here: https://github.com/jackkoppa/typesafe-vuex

It includes the fix for this bug, + specs to make sure you can use GetterHandler methods that still access root state correctly (my PR for that on this repo is here). I plan on keeping it the exact same as this package otherwise, since I've found no other issues up to this point.

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

4 participants