When attempting to utilize a computed property within another one or inside a method, I encountered the following error message:
Property 'comments' does not exist on type 'Vue'
import { Component, Vue } from 'vue-property-decorator'
@Component({
computed: {
comments(): Comment[] {
return this.$store.getters['comments/getComments'];
},
hasComments(): boolean {
return (0 !== (this as any).comments.length); // Property 'comments' does not exist on type 'Vue'
}
}
})
export default class Test extends Vue {
public get commentsCount(): number {
return (this as any).comments.length; // Property 'comments' does not exist on type 'Vue'
}
}
In order to avoid errors, I substituted (this as any).comments
, but it raises the question of why we would use typescript
and disregard type checking by using any
.