-
Notifications
You must be signed in to change notification settings - Fork 433
How to use ...mapGetters
with class components? Typescript errors
#109
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
Comments
You can declare the properties in the class or use a mapper like vuex-class. @Component({
computed: mapGetters(['foo'])
})
class App extends Vue {
foo: string
} |
Hi, given solution also generates error for me. Any tips most appreciated, thanks. below are the deps from package json if it makes any sense,
|
I also have been trying to figure out a way to remove that error, but have been unsuccessful. The only way that I have been able to suppress the error is by casting @Component({
computed: {
...mapGetters('ChartModule', {
charts: 'getCharts'
})
}
})
export default class ChartCompoment extends Vue {
created() {
console.log((this as any).charts)
}
} The other option that I have considered is using Conclusion: |
The key point is that when using TypeScript, you need to define properties not only for JS, runtime environment, but also for TS, static typing environment. Such @Component({
computed: {
...mapGetters('ChartModule', {
charts: 'getChars' // <- for runtime
})
}
})
class ChartComponent extends Vue {
charts!: any[] // <- for static type checking
created() {
console.log(this.charts)
}
} |
I tried both what @ktsn and @kaorun343 suggested but I am still kinda confused getters.ts
posts.module
PostsList.vue
essentially, I'm trying to do:
|
any new progress here? it seems mapGetters doesnot match class vue with well ts surport |
I think a
|
You can also convince Typescript by adding a object to extend:
|
This is nice to make things work, but of course it includes no type safety for these mapped getters, as they are all implicitly of type |
Thanks. Didn't realize it was coming in as |
You can simply type it instead of using @Component({ computed: { ...mapGetters(["fooThing"]) } })
export default class FooComponent extends Vue {
public fooThing!: Foo; // <- note the `!` which tells ts we care for this value being set.
created() { console.log(this.fooThing) }
} |
When I use
mapGetters
for computed properties in a class component, I get errors such that "Property '_____' does not exist` for all computed properties using mapGetters. Not sure if this is a typescript/ts-loader issue.The text was updated successfully, but these errors were encountered: