You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to implement a fairly basic, but polymorphic, active record style model system we run into issues with the type system not respecting this when used in conjunction with a constructor or template/generic.
I've posted before about this here, #5493, and #5492 appears to mention this behavior also.
I have recycled my example from #5493 into this ticket for further discussion. I don't have an immediate proposal for how to correct this but I wanted an open ticket representing the desire for such a thing.
Here is an example that outlines a model Factory which produces models. If you want to customize the BaseModel that comes back from the Factory you should be able to override it. However this fails because this cannot be used in a static member.
// Typically in a libraryexportinterfaceInstanceConstructor<TextendsBaseModel>{new(fac: Factory<T>): T;}exportclassFactory<TextendsBaseModel>{constructor(privatecls: InstanceConstructor<T>){}get(){returnnewthis.cls(this);}}exportclassBaseModel{constructor(privatefac: Factory<this>){}refresh(){// get returns a new instance, but it should be of// type Model, not BaseModel.returnthis.fac.get();}}// Application CodeexportclassModelextendsBaseModel{do(){returntrue;}}// Kinda sucks that Factory cannot infer the "Model" typeletf=newFactory<Model>(Model);leta=f.get();letb=a.refresh();
Activity
RyanCavanaugh commentedon Dec 1, 2015
Closing in favor of #5863