我正在将Vue.js
个组件迁移到TypeScript.在guide之后,我try 使用Vue.extend()
作为我的组件.我的组成部分是:
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
};
}
});
在上面的例子中,属性x
是react 性的,属性y
是非react 性的.然而,由于在TypeScript中扩展的工作方式,我无法让类型推断在property y
中工作.
我不能使用简单对象导出来定义我的组件,因为它开始为y
和x
抛出类型错误.
因为,现在我坚持将这个文件作为JS保存,或者将代码移动到vue-class-component
,这使我能够处理这个问题.然而,我不愿意改为vue-class-component
,因为这是一个库级别的代码.
有什么办法能让TypeScript
人开心吗?