Essentially i have the same question as this and this issue on Github, which unfortunately were both closed before being answered :/
I am using Vue with Typscript and the Vue Class Components.
What i need to do is to access a method of my (Vue-) Class from inside a watcher inside the @Component decorator.
I know that it's possible to access the data of a component with this.$data
, but what about methods.
My code works on runtime but produces compiletime-errors and errors in vscode ("Property 'clearInfo' does not exist on type 'Vue'.");
@Component({
watch: {
firstMesh(newMesh) {
if (newMesh === undefined) this.clearInfo(1); // this produces the errors
else this.showMeshInfo(newMesh, 1);
},
secondMesh(newMesh) {
if (newMesh === undefined) this.clearInfo(2);
else this.showMeshInfo(newMesh, 2);
},
},
})
export default class Info extends Vue {
clearInfo(whichMesh : number) {
...
}
showMeshInfo(mesh : any, index : number) {
....
}
}
You have two options:
Explanation
The explanation can be read on the links I left
Since you are defining the options in the decorator
@Component({...})
this will be available in the context where the class will be instantiated. Typescript won't know what exactly is available (we wish it was that smart). You will have to tell it, that's why we have thepublic clearInfo!: (wichMesh: number) => void;
part. If you don't know what this syntax means I will explain in short words and leave a link in the end:Non null assertion typescript Function signature typescript