【发布时间】:2019-04-13 10:31:09
【问题描述】:
我想用调用了它们的构造函数的片段来制作我的复合类型。我该怎么做或模仿这个?我不能在实现中调用 super(),也不能使用 extend,因为 派生类的构造函数必须包含一个“超级”调用。而且我不知道如何直接创建一个类型的对象人。
class bar {
j: number;
constructor() {
this.j = 20;
}
}
class baz {
i: number;
constructor() {
this.i = 10;
}
}
type person = bar & baz;
class p implements person {
i: number;
j: number;
constructor() {}
}
let _p = new p();
alert(_p.i) //undefined, want it to be 10
【问题讨论】:
标签: typescript types type-conversion