Open pravinbashyal opened 5 years ago
I played shortly with that idea in the past, but it makes the already troublesome dealing of TS with circular types even more horrendous. Instead, I suggest to use getEnv<Interface>()
in your implementation. If you get tired of repeating that, just make a utility function / view for that, so that you have to do it only once. (Some people create their own models for this, and compose these views into the actual models, so that the same utility view definition can be used in many places)
@mweststrate perhaps the idea of contexts from mobx-keystone could be used for this https://mobx-keystone.js.org/contexts
@mweststrate is there a sample for the utility? or a library around that use case?
Feature request
Is your feature request related to a problem? Please describe.
When I have to instantiate a model with env, I have to define the interface for the env at the point of instantiation. Take the following code for example
Describe the solution you'd like
Extend
types.model<T>
to accomodate optional dependenciestypes.model<T, DependenciesInterface?>
so the error will be thrown at compiletime as follows:Describe alternatives you've considered
Additional context
Are you willing to (attempt) a PR?