-
Notifications
You must be signed in to change notification settings - Fork 25
Closed
Labels
🍗 enhancementNew feature or requestNew feature or request🎈 releasedA fix that should close the issue has been releasedA fix that should close the issue has been released👨💻 has PRA PR that potentially fixes the issue existsA PR that potentially fixes the issue exists📑 merged to masterFeature done and merged to masterFeature done and merged to master
Description
I've been working around the limitations of generic models for a while, but I keep arriving at the same obstacles. I'm wondering whether there is any way to further improve generic models, so creating model classes is closer to what I would write in plain Typescript independent of mobx-keystone
.
The main problem is that I can't declare a generic model class with generic props:
class M<V extends number | string | boolean> extends Model({
value: prop<V>() // TS ERROR
}) {}
Current solutions:
- Use a model class factory and create model classes for all the generic types. This can lead to combinatorial explosion when composing models because I need to create as many models as I have combinations of generic types.
- Use an abstract base class where generic props are plain abstract class properties, inherit from the base class and make the abstract class properties real model props with concrete types. This also leads to combinatorial explosion when composing models.
With runtime types, it seems the equivalent of generics is a factory, so there may not be a solution in that case. But when using prop<T>()
there are no runtime types and I'm wondering whether there is a way to get better support for generic models in that case.
Metadata
Metadata
Assignees
Labels
🍗 enhancementNew feature or requestNew feature or request🎈 releasedA fix that should close the issue has been releasedA fix that should close the issue has been released👨💻 has PRA PR that potentially fixes the issue existsA PR that potentially fixes the issue exists📑 merged to masterFeature done and merged to masterFeature done and merged to master