ClickerMonkey / vuex-typescript-interface

Adding magical type safety to Vuex without additional code
MIT License
44 stars 4 forks source link

Typescript Errors #3

Closed Suruat closed 5 years ago

Suruat commented 5 years ago
  1. store: store as any shows me this message:

    Argument of type '{ router: VueRouter; store: any; render: (h: CreateElement) => VNode; }' is not assignable to parameter of type 'ComponentOptions<Vue, DefaultData, DefaultMethods, DefaultComputed, PropsDefinition<Record<string, any>>, Record<string, any>>'.

    Object literal may only specify known properties, and 'store' does not exist in type 'ComponentOptions<Vue, DefaultData, DefaultMethods, DefaultComputed, PropsDefinition<Record<string, any>>, Record<string, any>>'

  2. When I try to use mutations,

    const setLastName = mapMutations(['setLastName']);
    setLastName();`

    last line (setLastName()) throws an error:

    Cannot invoke an expression whose type lacks a call signature. Type '{ setFirstName: (payload?: string | undefined) => void; }' has no compatible call signatures.

Not sure, i it a problems with a package or I just using it wrong.

ClickerMonkey commented 5 years ago
  1. Did you import 'vuex' anywhere? It looks like a definition is missing.

I'll try to see if I can get it working without needing to reference vuex anywhere.

  1. mapX returns an object, so really it would be like this:
const mappings = mapMutations(['setLastName']);
mappings.setLastName();
ClickerMonkey commented 5 years ago

@Suruat #1 should be fixed in 0.1.5, and you won't have to use as any.

Suruat commented 5 years ago

One more question, if I may...

Is it possible to add type checking for this.$store.commit() way of using?

ClickerMonkey commented 5 years ago

I don't think that'll be possible anytime soon - there would need to be a few features added to TypeScript to get that to work.

Your best bet is to just use createHelpers and mapMutations from that to inject typesafe mutations into your Vue components.

rrandom commented 5 years ago

Hi, I'm still getting this error in current version, any ideas?

girvo commented 4 years ago

I'm getting a curious error when using createHelpers with local data state: for whatever reason, having both local state methods combined with mixed-in ...mapMutations blows away the inferred type definitions for data on this within the local mutation. Any ideas?