Context
I am aiming to construct a structure that consists of both abstract (represented in blue) and concrete elements (depicted in green):
https://i.sstatic.net/zBUAO.png
To achieve this, I referred to this particular solution which led me to develop the following code:
export abstract class BaseResourceModel {
public id?: string;
}
type ConcreteClass<C> = new (...args: any[]) => C;
export interface IBaseList<T extends BaseResourceModel>
extends ConcreteClass<BaseList<T>> {
}
export function TableMixin<T extends BaseResourceModel>() {
return function <B extends IBaseList<T>>(Base: B){
class Temporary extends Base implements OnInit {
(...)
}
return Temporary;
};
}
@Component({ template: '' })
export abstract class BaseList<T extends BaseResourceModel>
implements OnInit, OnDestroy {
(...)
}
@Component({ template: '' })
export abstract class BaseServerList<T extends BaseResourceModel> extends BaseList<T> {
(...)
}
Issue
I am unsure how to properly create the abstract BaseServerTable
, extending from BaseServerList
and using TableMixin
while retaining the generic
<T extends BaseResourceModel>
. The attempts I made resulted in errors as shown below:
- First attempt:
class DummyBaseServerList<T> extends BaseServerList<T> { }
@Component({ template: '' })
class BaseServerTable<T> extends TableMixin<BaseResourceModel, typeof DummyBaseServerList>()(BaseServerList<T>) {
(...)
}
Produces the error:
Expected 1 type arguments, but got 2.ts(2558)
- Second attempt:
class DummyBaseServerList<T> extends BaseServerList<T> { }
@Component({ template: '' })
class BaseServerTable extends TableMixin<BaseResourceModel>()(DummyBaseServerList) {
(...)
}
Results in:
No base constructor has the specified number of type arguments.ts(2508)
- Third attempt:
@Component({ template: '' })
class BaseServerTable<T> extends TableMixin<BaseResourceModel>()(BaseServerList<T>) {
(...)
}
Leads to:
Value of type 'typeof BaseServerList' is not callable. Did you mean to include 'new'?ts(2348)
Inquiry
How can I effectively implement this pattern? What am I overlooking? Despite thorough research, I have yet to find suitable examples or guidance for a scenario like this.