问题描述
如果我们在打字稿上有这个结构:
type A = {
v: number | string[]
}
interface B {
a: A;
}
class C implements B {
a = {
v: 3 // inference only with type number,string[] is lost
}
}
c = new C();
c.a.v = ['hello']; // not working,needs a: A on class C
// Working class must be:
class C implements B {
a: A = {
v: 3
}
}
有人知道是否有一种变通方法,以避免在每个类的“ a”上设置de type?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)