Open krnsk0 opened 1 year ago
I'm also interested by the mixins approach. Did you make any progress on this topic?
I'm also interested by the mixins approach. Did you make any progress on this topic?
I was never able to sort this out, sadly! Using an inheritance hierarchy instead.
I've got a project using
mobx-keystone
with a complex inheritance hierarchy, and I'm realizing I could simplify things if I switched to an inheritance pattern involving mixins.The Typescript docs recommend an approach they call "constrained mixins", in which factory functions accept a base class constrained to a type which they extend and return. I'd like to figure out how to do something like this with
ExtendedModel
.Here's where I'm at:
Is there a way to make this work? I suspect there's something I should be doing differently specifying the constraint on the type argument to the factories (
T Extends ModelClass<etc>
). Or it could be that I need some other way of describing the return type of the factories to use as constraints (e.g.type Countable = ReturnType<typeof makeCountable>
).Once I figure out a pattern that works, I'd be happy to contribute it back to the docs on inheritance if this would be useful, generally.