I am currently in the process of transitioning my Vue.js
components to TypeScript. In accordance with the recommendations provided in the documentation, I attempted to utilize Vue.extend()
for my component implementation. The code snippet for my component is as follows:
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 a reactive property
x: 10
};
}
});
In the above example, I have declared property x
as reactive and y
as a non-reactive property. Despite my efforts, I encountered difficulties in getting type inference to work seamlessly for property y
due to the complexities associated with augmentation in TypeScript.
The straightforward approach of using simple object export to define my component resulted in type errors being thrown for both properties x
and y
.
As a temporary workaround, I am maintaining this file in JavaScript or contemplating migrating my code to vue-class-component
which offers better support for handling such scenarios. However, I am hesitant to make the switch to vue-class-component
given that it involves introducing an additional library dependency at the project level.
If anyone has insights on how to appease TypeScript
in this situation, I would greatly appreciate the guidance.