I am migrating my Vue.js components to TypeScript. Following the guide, I tried to use Vue.extend() for my component. My component is:
import Vue from 'vue';
const Component = Vue.extend({
// type inference enabled
created() {
// `y` is non-reactive property
this.y = 20; // TYPESCRIPT THROWS ERROR
}
data() {
return {
// x is reactive property
x: 10
};
}
});
In above example, I have property x which is reactive and y as non-reactive property. However, I just cannot get type inference working for property y due the way augmentation works in TypeScript.
I cannot use simple object export for defining my component as it starts throwing a type error for both y and x.
For, now I am sticking to keeping this file as JS or move my code vue-class-component which enable me to handle this. However, I am reluctant to move to vue-class-component as it is a code at a library level.
Any solution to how I can make TypeScript happy?
computed: { y: function () { return 20 }}