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

How to use with vue-class-component? #10

Closed
NikitaKA opened this issue Mar 12, 2019 · 9 comments
Closed

How to use with vue-class-component? #10

NikitaKA opened this issue Mar 12, 2019 · 9 comments

Comments

@NikitaKA
Copy link

I'm trying to do something like that:

import foo from 'store/modules/foo';

@Component({
  methods: foo.mapMutations(['bar', 'baz'])
})

But got an error: Argument types do not match parameters on mapMutations.

@ilajosmanov
Copy link
Contributor

You should you spread operators

@NikitaKA
Copy link
Author

@ilajosmanov
But in tests there are no spread operator:

const Test = Vue.extend({
  methods: foo.mapMutations(['inc']),
  render(h): any {
    return h('div')
  }
})

I've tried to use spread, but that didn't help
image

There are no errors thrown from compiler and mutations typings do not work too.

@NikitaKA
Copy link
Author

NikitaKA commented Mar 12, 2019

I found that problem appears when that's done in .vue file. Everything works fine when doing same thing in regular .ts file... Is there any way to fix this?

image

@ktsn
Copy link
Owner

ktsn commented Mar 13, 2019

The example code should work properly. It does not matter whether you use spread operator or not.
If you provide self-contained reproduction, we would easily find the root cause of your problem.

@NikitaKA
Copy link
Author

NikitaKA commented Mar 13, 2019

@ktsn
I have created simple project with Vue CLI for demonstration: https://github.com/NikitaKA/vuex-smart-module-bug (sorry if it's not).
Problem is not in spread operator, but in mapper and .vue file.

image

@ktsn
Copy link
Owner

ktsn commented Mar 13, 2019

  • TypeScript does not infer this type of component from component options of decorator. So it is actually normal to produce error like setTest does not exist.
  • If you want it to infer this type, you should use Vue.extend for mappers and inherit it.
import { Component, Vue } from 'vue-property-decorator';
import TestStore from './module';

const Super = Vue.extend({
  methods: TestStore.mapMutations(['setTest'])
})

@Component
export default class App extends Super {
  mounted() {
    this.setTest(true);
  }
}

@ktsn ktsn closed this as completed Mar 13, 2019
@NikitaKA
Copy link
Author

@ktsn I did right as you said, but it doesn't work. But it still works fine in a regular .ts file. I updated the project.

image

@ktsn
Copy link
Owner

ktsn commented Mar 13, 2019

That is likely your editor or build environment issue. It does not happen on my side with your reproduction. Please check whether the actual build process passes type check.

@NikitaKA
Copy link
Author

NikitaKA commented Mar 13, 2019

Yes, you were right - there is error, types working. It seems that WebStorm can't recognize that... Sorry for bother you, thanks for help!

UPDATE
Jetbrains support recommended me to install 2019.1 EAP (which adding better Typescript support in .vue files) and all errors are gone!

Shybert added a commit to Shybert/tamasi that referenced this issue Apr 10, 2019
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