mobxjs / mobx-state-tree

Full-featured reactive state management without the boilerplate
https://mobx-state-tree.js.org/
MIT License
6.94k stars 640 forks source link

Error Messaging when Types don't match #1966

Closed Vercjames closed 1 year ago

Vercjames commented 2 years ago

value <TYPE A> is not assignable to type: <TYPE B> (Value is not a <TYPE B>). is a common message when changing a value in Mobx State Tree. However it lacks enough definition to find the code culprit(s) leading to a dead end error message or, in some case, a complete app crash with little to no data references.

Is your feature request related to a problem? Please describe. Yes. There was an entire ticket here but a bot auto closed it and I believe more context was warranted.

Describe the solution you'd like A more descriptive options from the error messaging. and a solution to the inline Typescript errors.

Describe alternatives you've considered I've tried wrapping the model reference in additional catch layers but have been unsuccessful.

Additional context You can view my repo illustrating the problem here And I made a Youtube Video about the whole issue as well.

Are you willing to (attempt) a PR?

coolsoftwaretyler commented 1 year ago

I also run into this from time to time. I will say that I've rarely needed much more from MST in way of debugging, because I usually know what model or models I've been mucking about with.

But it can be frustrating when receiving information from something like a third party API that changes.

In the reproduction you've provided, would your ideal state be an addition to the error message that basically says something like:

setDescription: <TYPE A> is not assignable to type: <TYPE B>
coolsoftwaretyler commented 1 year ago

I'm going to convert this to a discussion, because I don't think it's really a bug, but I do think it's excellent feedback, and we should consider improving this developer experience.