Breaking Changes
- Eliminate
NonEmptyObject
by @thegedge in #2152 - Improved typing for union types by @thegedge in #2151
- fix #1530 array clear replace should produce one patch by @BrianHung in #2073
- Feat/has env and getenv changes by @coolsoftwaretyler in #2163
Features
- Added a new feature,
hasEnv
, to support #2163
Fixes
- Union types will now be fixed, but this also may break TypeScript for some users
- Array operations produce condensed patches when we can, but this may break for some users who relied on the patch generation as it was
- fix: do not mutate properties object by model constructor by @dangreen in #2176
- Fix/get members 2173 by @evinosheaforward in #2174
- fix: #2138 linter issues with fail function by @JuanJo4 in #2171
Tests
- Test: convert to bun:test for our tests, remove codecov by @coolsoftwaretyler in #2149
Docs
- Docs/update docs homepage by @coolsoftwaretyler in #2141
- docs: fix typos in docs update by @coolsoftwaretyler in #2142
- Docs: add comparison between React Context/Reducer by @coolsoftwaretyler in #2158
Docs: add recipe for mst-form-type by @sherlockwang in #2168 - docs: fix broken link by @kylemeenehan in #2165
- docs: update TypeScript tips by @coolsoftwaretyler in #2166
- docs: add recipe for auto-generated property setters by @coolsoftwaretyler in #2169
- docs: correct bun run test to bun run test:all for new contributers by @evinosheaforward in #2177
Community/Developer Changes
- Chore/use bun as a package manager and script runner by @coolsoftwaretyler in #2148
- Bump typescript from 3.9.10 to 5.3.3 by @thegedge in #2146
- chore: remove unused, unnecessary custom Omit type #2167
New Contributors
- @thegedge made their first contribution in #2146
- @sherlockwang made their first contribution in #2168
- @dangreen made their first contribution in #2176
- @evinosheaforward made their first contribution in #2174
Full Changelog: v5.4.2...v6.0.0
Migration Guide from v5 to v6
TypeScript update
Make sure you're using TypeScript 5.3.3
, and you have the following compiler flags:
{
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true
}
Or the shorthand:
{
"strict": true,
"noImplicitReturns": true
}
Removing $nonEmptyObject
We removed the $nonEmptyObject
key from the ModelCreationType
. For the most part, this was an internal feature that would only have shown up in TypeScript errors. There is no runtime change, but if you have any custom typings that relied on something like [$nonEmptyObject]
- you should be able to eliminate those.
Union Type Changes
In the past, named enumerations had more specific type than unnamed enumerations. You may have some TypeScript errors where you were using anonymous enumerations. You can type those with the union of literal values inside the enumeration now.
import { t } from "mobx-state-tree";
/**
* In MobX-State-Tree 5.4.1, this is typed as:
* ISimpleType<"Red" | "Orange" | "Green">
*/
const namedEnum = t.enumeration("Color", ["Red", "Orange", "Green"]);
/**
* In MobX-State-Tree 5.4.1, this is typed as:
* ISimpleType<string>
*/
const anonymousEnum = t.enumeration(["Red", "Orange", "Green"]);
/**
* If you use mobx-state-tree@^6.0.0, both of these will be typed as:
* ISimpleType<"Red" | "Orange" | "Green">
*/
This has also fixed #1525 and #1664
For #1525, If you had models with properties that were unions including other models, you may have done some type assertions to resolve the issue. This should no longer be necessary. In most cases, we don't expect this to show up as errors. But the inferred types have changed. Look through your codebase for unions of models in the properties of other models, and if you hit any issues, you may be able to use better typing form here on out.
The issue presented itself in #1664 when using types with different creation and instance types which were passed to unions inside of arrays. If you see more TypeScript errors aside from the other items mentioned, look for types.union
that creates a union which includes Array
, Map
, or Model
types. If you had any custom type assertions, you may no longer need those.
Array operation patch changes
When an Array
type calls clear
, or splices itself from index 0
, the generated patch is different. We have shortened the operations to be a patch like:
op: "replace", path: "", value: []
If you use onPatch
and expect any specific shape of patches from Array.clear
or Array.splice
, you may need to update your app logic to handle the changed patch generation.
getEnv now throws
If you call getEnv
and there is no environment, it will now throw an error. Previously, it would return an empty object.
Check your codebase for getEnv
calls, and guard against this error with hasEnv
, which will return true
if the current state tree has an environment, or false
if not.