You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix typescript types after type optimization and cast, add castToSnapshot and castToReferenceSnapshot (#1074)
* fix ts types and cast, add castToSnapshot
* make castToSnapshot accept instance or snapshot
* test fix
* fixed maybe and maybenull cases
* fix for map put set
* added some comments
* lots of fixes, added castToReferenceSnapshot, made array ops not need cast
* small tweak to test
* api test fix
* removed the now unecessary IComplexType
Copy file name to clipboardExpand all lines: README.md
+28-8Lines changed: 28 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -924,10 +924,10 @@ Note that since MST v3 `types.array` and `types.map` are wrapped in `types.optio
924
924
-`types.late(() => type)` can be used to create recursive or circular types, or types that are spread over files in such a way that circular dependencies between files would be an issue otherwise.
925
925
-`types.frozen(subType? | defaultValue?)` Accepts any kind of serializable value (both primitive and complex), but assumes that the value itself is **immutable** and **serializable**.
926
926
`frozen` can be invoked in a few different ways:
927
-
-`types.frozen()` - behaves the same as types.frozen in MST 2.
928
-
-`types.frozen(subType)` - provide a valid MST type and frozen will check if the provided data conforms the snapshot for that type. Note that the type will not actually be instantiated, so it can only be used to check the shape of the data. Adding views or actions to SubType would be pointless.
929
-
-`types.frozen(someDefaultValue)` - provide a primitive value, object or array, and MST will infer the type from that object, and also make it the default value for the field
930
-
- (Typescript) `types.frozen<TypeScriptType>(...)` - provide a typescript type, to help in strongly typing the field (design time only)
927
+
-`types.frozen()` - behaves the same as types.frozen in MST 2.
928
+
-`types.frozen(subType)` - provide a valid MST type and frozen will check if the provided data conforms the snapshot for that type. Note that the type will not actually be instantiated, so it can only be used to check the shape of the data. Adding views or actions to SubType would be pointless.
929
+
-`types.frozen(someDefaultValue)` - provide a primitive value, object or array, and MST will infer the type from that object, and also make it the default value for the field
930
+
-(Typescript) `types.frozen<TypeScriptType>(...)` - provide a typescript type, to help in strongly typing the field (design time only)
931
931
-`types.compose(name?, type1...typeX)`, creates a new model type by taking a bunch of existing types and combining them into a new one.
932
932
933
933
## Property types
@@ -993,8 +993,10 @@ See the [full API docs](API.md) for more details.
993
993
|[`addMiddleware(node, middleware: (actionDescription, next) => any, includeHooks)`](API.md#addmiddleware)| Attaches middleware to a node. See [middleware](docs/middleware.md). Returns disposer. |
994
994
|[`applyAction(node, actionDescription)`](API.md#applyaction)| Replays an action on the targeted node |
995
995
|[`applyPatch(node, jsonPatch)`](API.md#applypatch)| Applies a JSON patch, or array of patches, to a node in the tree |
996
-
|[`cast(nodeOrSnapshot)`](API.md#cast)| Cast a node instance or snapshot to a node so it can be used in assignment operations |
997
996
|[`applySnapshot(node, snapshot)`](API.md#applysnapshot)| Updates a node with the given snapshot |
997
+
|[`cast(nodeOrSnapshot)`](API.md#cast)| Cast a node instance or snapshot to a node instance so it can be used in assignment operations |
998
+
|[`castToSnapshot(nodeOrSnapshot)`](API.md#casttosnapshot)| Cast a node instance to a snapshot so it can be used inside create operations |
999
+
|[`castToReferenceSnapshot(node)`](API.md#casttoreferencesnapshot)| Cast a node instance to a reference snapshot so it can be used inside create operations |
998
1000
|[`createActionTrackingMiddleware`](API.md#createactiontrackingmiddleware)| Utility to make writing middleware that tracks async actions less cumbersome |
999
1001
|[`clone(node, keepEnvironment?: true \| false \| newEnvironment)`](API.md#clone)| Creates a full clone of the given node. By default preserves the same environment |
1000
1002
|[`decorate(handler, function)`](API.md#decorate)| Attaches middleware to a specific action (or flow) |
Copy file name to clipboardExpand all lines: changelog.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,6 @@
1
+
# 3.8.0
2
+
3
+
- Added castToSnapshot/castToReferenceSnapshot methods for TypeScript and fixed some TypeScript typings not being properly detected when using SnapshotIn types through [#1074](https://github.com/mobxjs/mobx-state-tree/pull/1074) by [@xaviergonz](https://github.com/xaviergonz)
1
4
- Fixed redux middleware throwing an error when a flow is called before it is connected [#1065](https://github.com/mobxjs/mobx-state-tree/issues/1065) through [#1079](https://github.com/mobxjs/mobx-state-tree/pull/1079) by [@mkramb](https://github.com/mkramb) and [@xaviergonz](https://github.com/xaviergonz)
2
5
- Made `addDisposer` return the passed disposer through [#1059](https://github.com/mobxjs/mobx-state-tree/pull/1059) by [@xaviergonz](https://github.com/xaviergonz)
0 commit comments