Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make array and map types optional by default #906

Closed
mweststrate opened this issue Jun 29, 2018 · 3 comments
Closed

Make array and map types optional by default #906

mweststrate opened this issue Jun 29, 2018 · 3 comments
Labels
breaking change Breaking change
Milestone

Comments

@mweststrate
Copy link
Member

No description provided.

@mweststrate mweststrate added the breaking change Breaking change label Jun 29, 2018
@mweststrate mweststrate added this to the 3.0 milestone Jun 29, 2018
@mweststrate
Copy link
Member Author

array and map types will be optional by default when used directly as model properties.

Tried making child objects optional as well, but this became very confusing in combination with maybe and such (since undefined would then be an acceptable value, leaving a field in a snapshot would be inferred to {} instead of null, etc..

@mweststrate
Copy link
Member Author

Scheduled for 3.0, closing

agilgur5 added a commit to agilgur5/mobx-state-tree that referenced this issue Sep 2, 2018
- a8c7c60 implemented this but did not change the docs
xaviergonz added a commit that referenced this issue Sep 2, 2018
add docs re: optional map / array types of #906
@jlgrall
Copy link

jlgrall commented Sep 26, 2018

How to make them mandatory when I need it ?

Seems to me the only way would be adding a refinement() over the current implicit optional() wrapping:

var MyList = types.model({
	list: types.refinement(types.array, v => v !== undefined);
});

Would this refined type still return true with a call to isOptionalType(value) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Breaking change
Projects
None yet
Development

No branches or pull requests

2 participants