mrcrowl / vuex-typex

Typescript builder for strongly-typed access to Vuex Store modules
MIT License
193 stars 22 forks source link

Problem with Examples in Repository #11

Closed Gregoyle closed 6 years ago

Gregoyle commented 6 years ago

I'm having an issue with the examples in this library and my own code. I was hoping someone could ellucidate what I might be doing wrong:

When I try to use the examples in this repo I run into an issue with dispatch:

Argument of type '(context: ActionContext<any, RootState>, payload: any) => void' is not assignable to parameter of type 'ActionHandler<any, RootState, any, void>'.
  Types of parameters 'context' and 'context' are incompatible.
    Type 'BareActionContext<any, RootState>' is not assignable to type 'ActionContext<any, RootState>'.
      Property 'dispatch' is missing in type 'BareActionContext<any, RootState>'.

I'm wondering if you have run into this problem in your own work? It's keeping me from making effective use of the library. It only happens when I type the context in an action:

function addAppError(context: StatContext, payload) {

And the dispatch: builder.dispatch(addAppError). Even though the builder is made correctly:

const builder = storeBuilder.module<IStatsState>(moduleName, statsStoreState);
type StatContext = ActionContext<IStatsState, RootState>;

Any thoughts? I see the same error if I try the basket example from this repo.

victorgarciaesgi commented 6 years ago

@Gregoyle can you link your repo code so I can see what's going on?

gkinsman commented 6 years ago

You need to use BareActionContext instead of ActionContext - I'm not sure when this changed but it works, sample here: https://github.com/gkinsman/vue-types-demo.