Here is example if you need parameters in constructor:
class Sample {
public innerField: string;
constructor(data: Partial<Sample>) {
this.innerField = data.innerField;
}
}
export class GenericWithParams<TType> {
public innerItem: TType;
constructor(data: Partial<GenericWithParams<TType>>, private typePrototype: new (i: Partial<TType>) => TType) {
this.innerItem = this.factoryMethodOnModel(data.innerItem);
}
private factoryMethodOnModel = (item: Partial<TType>): TType => {
return new this.typePrototype(item);
};
}
const instance = new GenericWithParams<Sample>({ innerItem : { innerField: 'test' }}, Sample);