Background
I want to create the following structure (blue are abstract and green are concrete):
So I followed this answer and created 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> {
(...)
}
Problem
I don't know exactly how to create the abstract BaseServerTable extended from BaseServerList and composed with TableMixin keeping the generic <T extends BaseResourceModel>on it. I get the following errors:
- First attempt:
class DummyBaseServerList<T> extends BaseServerList<T> { }
@Component({ template: '' })
class BaseServerTable<T> extends TableMixin<BaseResourceModel, typeof DummyBaseServerList>()(BaseServerList<T>) {
(...)
}
Results in: 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>) {
(...)
}
Results in: Value of type 'typeof BaseServerList' is not callable. Did you mean to include 'new'?ts(2348)
Question
How to implement this pattern? What I am missing? I've searched everywhere about samples a pattern like this
