Update:
In response to the feedback from @artur-grzesiak below, we have made changes to the playground to simplify it. We removed a poorly named interface
method and now expect the compiler to throw an error for the unimplemented getInterface
. However, the error is not being thrown:
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",
// }
// }
}
The Country Class should enforce the abstract contract inherited from the AbstractBaseObject Class, which declares an abstract property interface
. The Class Country should implement the BaseDataObjectInterface, which requires the same property/accessor, but the TypeScript compiler does not raise any error as shown in this TypeScript playground.
Could there be something I am overlooking here?