【发布时间】:2019-12-05 00:56:45
【问题描述】:
我有一个 Vue 组件,它有一个使用装饰器定义的属性:
import { Component, Vue } from "vue-property-decorator"
@Component({
props: {
myId: String,
},
})
class TestProp extends Vue {
myFunction(obj: any) {
return obj[this.myId] // here tslint complains: "Property 'myId' does not exist on type 'TestProp'."
}
}
我可以通过将this 转换为any 来避免类型错误:
myFunction(obj: any) {
return obj[(this as any).myId]
}
但这与其说是解决方案,不如说是一种解决方法。
我猜编译器不知道@Component 装饰器定义的属性?
有什么想法吗?
【问题讨论】:
-
请分享完整的错误详情
标签: javascript typescript vue.js tslint