Mobx-state-tree: model attributes named "name" of type string causes Error

Created on 24 Jan 2018  ·  5Comments  ·  Source: mobxjs/mobx-state-tree

```javascript
var Beer = types.model("Beer", {
name: types.string,

cells: types.maybe(
  types.map(
    types.late(function() {
      return Beer;
    })
  )
)

});

var b = Beer.create({ id: uuid() });
unprotect(b);
var b2 = Beer.create({ id: uuid() });
b.cells = {};
b.cells.put(b2);

var snapshot = getSnapshot(b);
var b1 = Beer.create(snapshot);

throws on `applySnapshot` but changing the one line on how name is declared as so

``` javascript
var Beer = types.model("Beer", {
    id: types.identifier(),
    name: ""

does not.

Most helpful comment

For future readers: Note that name: types.string makes string required,
but name: "" will make name optional, and have it defaulted to ""

Op ma 29 jan. 2018 om 23:18 schreef John Wright notifications@github.com:

Thanks for the reply but I moved on and closed this. I decided to use
straight mobx to better handle this design.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/mobxjs/mobx-state-tree/issues/620#issuecomment-361406392,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABvGhPOi6evmFGVJwabuw-kWwP4PFYbIks5tPkPBgaJpZM4Rqrko
.

All 5 comments

Actually I am not sure I identified that correctly, closing until I can narrow down further.

Is it related to types.maybe() by any chance? Does the error tell you that cells is not optional even though you defined it with types.maybe()?

Thanks for the reply but I moved on and closed this. I decided to use straight mobx to better handle this design.

For future readers: Note that name: types.string makes string required,
but name: "" will make name optional, and have it defaulted to ""

Op ma 29 jan. 2018 om 23:18 schreef John Wright notifications@github.com:

Thanks for the reply but I moved on and closed this. I decided to use
straight mobx to better handle this design.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/mobxjs/mobx-state-tree/issues/620#issuecomment-361406392,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABvGhPOi6evmFGVJwabuw-kWwP4PFYbIks5tPkPBgaJpZM4Rqrko
.

👍🏼 thanks!

On Jan 30, 2018, at 2:42 AM, Michel Weststrate notifications@github.com wrote:

For future readers: Note that name: types.string makes string required,
but name: "" will make name optional, and have it defaulted to ""

Op ma 29 jan. 2018 om 23:18 schreef John Wright notifications@github.com:

Thanks for the reply but I moved on and closed this. I decided to use
straight mobx to better handle this design.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/mobxjs/mobx-state-tree/issues/620#issuecomment-361406392,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABvGhPOi6evmFGVJwabuw-kWwP4PFYbIks5tPkPBgaJpZM4Rqrko
.


You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub https://github.com/mobxjs/mobx-state-tree/issues/620#issuecomment-361535445, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAQ91CECUjaHSu-YTYj4wtTubSO_W3Jks5tPuQfgaJpZM4Rqrko.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FredyC picture FredyC  ·  3Comments

lishine picture lishine  ·  4Comments

EricForgy picture EricForgy  ·  4Comments

elado picture elado  ·  4Comments

lidermanrony picture lidermanrony  ·  3Comments