【发布时间】:2020-11-04 07:34:46
【问题描述】:
interface Intf {
prop: ComputedRef<string>;
}
const obj = {} as Intf;
console.log(obj.prop.value);
我有上面的代码,看起来和我预期的一样好。我可以访问obj.prop.value,并且打字稿没有抛出任何错误。但是,当我将这个ComputedRef<string> 放在另一个反应对象中时,我无法将其取回,因为打字稿说prop 的类型是string 而不是ComputedRef<string>。让我们看看以下代码:
interface Intf {
prop: ComputedRef<string>;
}
const re = reactive({
obj: {} as Intf
});
console.log(re.obj.prop.value); // typescript shown error on this line, `re.obj.prop` is with type `string` instead of `ComputedRef<string>`. At the moment, I cannot retrieve `prop.value` by accessing `prop` as well, since prop is a `ComputedRef<string>` and I should get its value by accessing `prop.value`!!
【问题讨论】:
标签: typescript reactive-programming typescript-typings reactive vuejs3