I have some issue with generic property. And some solution for it. Regarding code below can you propose some other solution ?
interface IConfig{
property?: number;
}
interface IChildConfig extends IConfig{
otherProperty?: number;
}
class Base<T extends Base<any, IConfig>, U extends IConfig>{
protected _config: U | IConfig = {
property: 10
};
public config(){
return <U>this._config;
}
}
class Child extends Base<Child, IChildConfig>{
protected _config: IChildConfig = {
property: 20,
otherProperty: 10
}
}
let a = new Child(),
b = new Base();
a.config();
b.config();
In example I set _config property type to U | IConfig to avoid errors. If I'll remove "| Config" part compilator will raise errors. As I understand type U must be equal or extend IConfig interface.