Edit:
Following the comment from @artur-grzesiak below, We've modified the playground for a simpler version, without a badly named interface method. where we would still expect the compiler to throw an error for the not implemented getInterface, but it does not do so:
type GConstructor<T = {}> = abstract new (...args: any[]) => T;
// Raw objects interfaces
interface IBaseDataObject {
readonly id: string;
}
// Name Pattern
interface Name {
name: string;
}
// interfaces that classes must implement
interface BaseDataObjectInterface<T extends IBaseDataObject> {
readonly id: string;
readonly interface: T;
}
abstract class AbstractBaseObject<T extends IBaseDataObject> {
readonly id: string;
abstract readonly interface: T
constructor(
iBaseDataObject: T
) {
this.id = iBaseDataObject.id;
}
}
type AbstractBaseObjectCtor<T extends IBaseDataObject> = GConstructor<AbstractBaseObject<T>>;
// Country interface, class and instances
interface ICountry extends IBaseDataObject, Name {}
function NameAbstractMixin<TBase extends AbstractBaseObjectCtor<T>, T extends IBaseDataObject & Name>(Base: TBase) {
abstract class NamedBase extends Base implements Name {
readonly name: string;
constructor(...args: any[]) {
super(...args)
this.name = args[0].name;
}
}
return NamedBase;
}
class Country extends NameAbstractMixin(AbstractBaseObject<ICountry>) implements BaseDataObjectInterface<ICountry> {
// get interface(): ICountry {
// return {
// id : "hello",
// name: "France",
// }
// }
}
Country Class should enforce the abstract contract inherited from the AbstractBaseObject Class which declares an abstract property interface and the Class Country should implements BaseDataObjectInterface which requires the same property/accessor but typescript compiler doesn't raise any error as you can see on this typescript playground.
Am I missing something here?