TypeScript/tests/cases/compiler/mixinIntersectionIsValidbaseType.ts
Wesley Wigham 6c2ae12559
Relax the constraints of isValidBaseType to allow base types to be constructor types (#33146)
* Relax the constraints of isValidBaseType to allow base types to be constructor types

* Fix nit

* Reduce confusion between isConstructorType and isValidBaseType

* Update comment
2019-09-23 15:58:03 -07:00

27 lines
751 B
TypeScript

export type Constructor<T extends object = object> = new (...args: any[]) => T;
export interface Initable {
init(...args: any[]): void;
}
/**
* Plain mixin where the superclass must be Initable
*/
export const Serializable = <K extends Constructor<Initable> & Initable>(
SuperClass: K
) => {
const LocalMixin = (InnerSuperClass: K) => {
return class SerializableLocal extends InnerSuperClass {
}
};
let ResultClass = LocalMixin(SuperClass);
return ResultClass;
};
const AMixin = <K extends Constructor<Initable> & Initable>(SuperClass: K) => {
let SomeHowOkay = class A extends SuperClass {
};
let SomeHowNotOkay = class A extends Serializable(SuperClass) {
};
};