Replies: 1 comment 1 reply
-
|
Does this section of the docs help? https://mobx-keystone.js.org/classModels#factory-pattern--generics |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to write a function to create many models that all extend from the same base model but have a couple additional properties. I have a large union type to model so I want to make it easy to create each individual case. I'm struggling to figure out how to do this in a generic way. I don't think I understand some deeper parts of typescript well enough to figure out why this isn't working.
Here's a shot at a generic function to make a new model from a base model but with potentially added props:
This results in the following error:
It was intended to be used like so:
I can't find any way to add generic props to an ExtendedModel. It seems the only way to model this right now is to type out a separate class for each case of the union or forego type checking and optional values.
Beta Was this translation helpful? Give feedback.
All reactions