-
Notifications
You must be signed in to change notification settings - Fork 644
SnapshotIn Type unexpectedly changed behavior in MST version 7 (when upgrading from 6) #2254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Curious about that expectation, @jrmyio. Specifically, why don't think you an instance should be acceptable as an input snapshot? I ask because an instance (in most cases) satisfies the interface of an input snapshot. Note that this choice was intentional. We implemented it in #2199, and you can see links to various discussions on that decision, #1568 (comment) in particular. |
Thanks for your quick reply. I agree it's good to support instances when using I am not so convinded one should call an object with possible instances in it a Imo the MST 6 The reason I ran into issues is that I've been using this Maybe another type helper could be added but I cannot think of a name other than SnapshotIn because to me that made perfect sense. |
Hey @jrmyio - I'm sorry about the mixup this caused on your end. That's the trouble with breaking changes. I'm inclined to agree with @thegedge here (we talked about it at length at the time). I don't think it makes sense to reverse the decision, but I'd be open to a PR to add another type helper, or I'd be curious if you can utilize SnapshotOut here instead? |
Alternatively, I may have been able to take a far more sophisticated approach, where I could derive an interface that matches the model instance type, but only has the identifier attribute. So something like: const MyModel = types.model({
myIdentifier: types.identifierNumber,
tags: types.array(types.string),
description: types.string,
})
// { myIdentifier: number }
type InstanceInput = AsCreationParam<MyModel>; The idea would be that we'd have a fairly primitive interface, but [EDIT] mobx-state-tree/src/types/utility-types/reference.ts Lines 363 to 365 in cb26163
|
In MST 6 when you do
SnapshotIn<typeof ParentType>
it always returned a simple type. Since MST 7 any child / sub type insideParentType
seem to return theirSnapshotOrInstance
version instead ofSnapshotIn
of the child type.I would expect SnapshotIn to always expect a simple JSON rather than allow instances to still be part of the Snapshot type.
Here you can see the MST 6 behavior:
https://codesandbox.io/p/sandbox/angry-vaughan-4zcrps
MST 7 behavior:
https://codesandbox.io/p/devbox/mst-6-forked-yx22tx
Where I think it makes it a mistake in above sandbox:
// UNEXPECTED: // getSomething() is valid here?
The text was updated successfully, but these errors were encountered: