【发布时间】:2019-08-15 15:08:41
【问题描述】:
我需要创建 HOF(高阶函数),它将修改/添加属性到提供的类的原型。有可能吗?
interface IStore {
new (): {};
}
interface IWatchable {
new() : {
watch: boolean;
};
}
const Store = <T extends IStore>(clazz: T): T & IWatchable => {
return class extends clazz {
watch = true;
};
};
class X extends Store(class {})
// ^^^^^^^^^^^^^^
// Base constructors must all have the same return type.
【问题讨论】:
标签: typescript types constructor casting extends