refinement doesn't run type checks in production

Author: davetapleyCreated Sep 19, 2022Updated Feb 17, 2025
Labelsbrainstorming/wild ideabreaking changehelp/PR welcomelevel: intermediatenot a bug

Bug report

  • I've checked documentation and searched for existing issues
  • I've made sure my project is based on the latest MST version
  • Fork this code sandbox or another minimal reproduction.

Sandbox link or minimal reproduction code

  1. Open: https://codesandbox.io/s/mst-refinement-dev-mode-xk0w34?file=/.env
  2. Press 'Add' button

Describe the expected behavior

Crash with unhandled exception:

[mobx-state-tree] Error while converting `{"title":""}` to `Todo`:

because I modified Todo.js to be:

javascript
types.refinement(types.string, (str) => str.length > 0),

Describe the observed behavior

It doesn't crash.

Note that if you delete the .env file I added (putting it back in to development mode) the exception is raised.