Struggling to call a method in a Vue root component from a lifecycle method in typescript? See below for a simple example that showcases this issue:
import Vue from "vue";
class Game {
a: number;
b: number;
constructor() {
this.a = 3;
this.b = 4;
}
}
new Vue({
el: "#calculator",
data: {
game: null
},
methods: {
// bound to a button
reset: function() {
this.game = new Game();
},
// bound to a button
add: function() {
this.game.a += 1;
}
},
beforeCreate() {
this.reset();
}
});
Encountering the following typescript compilation error:
src/test.ts:28:8 - error TS2339: Property 'reset' does not exist on type 'Vue'.
28 this.reset();
It seems that typescript only recognizes properties defined in data
as part of this
, overlooking those defined in methods
. Any suggestions on how to resolve this issue?
Keep in mind, this would work perfectly in javascript