Reputation: 737
I'm getting an issue that only seems to be a problem with my compiler. It doesn't like that it can't find properties I've defined in the data section. If I replace 'this' with '(this as any)' it runs just fine. That leads me to believe that I have an issue with typescript that I need to fix. The error message is very specific to my situation but I'm not sure how to fix it.
EDIT to add shims-vue.d.ts
declare module '*.vue' {
import Vue from 'vue';
export default Vue;
}
Upvotes: 3
Views: 779
Reputation: 737
What ended up fixing this was my declarative statement. My error:
export default {
name: 'Home',
components: {
...
},
...
};
The fix:
export default Vue.extend({
name: 'Home',
components: {
...
},
...
});
Upvotes: 1
Reputation: 7553
It appears computed properties may require explicit type annotations, as in this answer. Instead of
items() {
...
}
you'd have
items(): ItemType[] {
...
}
Typescript should then understand the this
reference. It's also worth considering the class component syntax, which in my experience is better suited for typescript in Vue 2 (this issue wouldn't happen).
Upvotes: 1