【发布时间】:2021-02-24 16:10:20
【问题描述】:
此代码在原版 javascript 中运行良好
const enhancementA = {
a() {
return this.c + 1;
},
};
const enhancementB = {
b() {
return this.c + 2;
},
};
class C {
c = 0;
constructor() {
Object.assign(this, enhancementA, enhancementB);
}
}
const d = new C();
d.a() // 1
d.b() // 2
d.c // 0
但它在打字稿中不起作用
d.a() // TS2339: Property 'a' does not exist on type 'C'.
d.b() // TS2339: Property 'b' does not exist on type 'C'.
我怎样才能让它在打字稿中工作?
【问题讨论】:
标签: javascript typescript class inheritance