-
Notifications
You must be signed in to change notification settings - Fork 642
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
Additional fields #66
Comments
Good point, I think that should not be the behavior, I was tinkering about that already. Currently |
How I can help with this issue? |
I think this can best and easily be fixed once #65 is done, which features many type system improvements |
Yeah, that should be correct @mwestrate! Btw is it a good thing to silently ingore those properties? |
I started an investigation of a problem for myself. Because I need this issue resolved :D const Factory = createFactory({ a: number });
Factory.is({ b: string }) // true like a Factory.is({}) What do you think about this? |
@mweststrate But |
@zetoke Yes indeed, it yields false atm because it checks over the count of keys |
@zetoke @mattiamanzati, eh no, should return |
@mweststrate @mattiamanzati but in the latest release (without my modifications) the "same" logic:
It's bacause |
@zetoke Factory.is({ id: 5, name: "hello", additionalKey: false }) // => false, because the number of keys is > than the allowed |
@zetoke I think |
@mweststrate Yes indeed |
@mattiamanzati btw, should |
yep. But if number of keys < keys in snapshot - everything is ok for mobx-state-tree for now. That have been my point.
Probably. What's about just |
@mweststrate string("") is the same as doing "", so it will fallback to https://github.com/mobxjs/mobx-state-tree/blob/master/src/types/object.ts#L62-L66 and being a primitive! So the only correct one is withDefault(string, "")! With the new syntax that issue will be solved, because it will be string.create("") vs. withDefault(string, "") and that create will let you understand that you are crating an instance instead of passing a type |
@mweststrate The main problem is |
Imho behavior shoud be: const Item = createFactory({
id: types.number,
name: types.string,
})
Item.is({}) // false, missing name and id
Item.is({ id: 3}) // false, missing name
Item.is({ id: 3, name: ""}) // OK
Item.is({ id: 3, name: "", description: ""}) // OK, but description will be 'lost' upon instantation
createFactory({
id: types.number,
name: types.string("")
}).is({ id: 3 }) // OK, name is lacking but has a default |
Only correction is the following createFactory({
id: types.number,
name: types.withDefault(types.string, "")
}).is({ id: 3 }) // OK, name is lacking but has a default |
@mweststrate yep, that make sense. I have the same picture in my head. |
Hey, guys!
Thanks a lot for this great lib 👍
Can you clarify one question for me?
I have code:
Sheme from API:
Everything is ok.
But then at the API backend guys adding new non-breaking (not for us) field.
For example:
And we getting error and stack trace.
How can I avoid/handle this case?
Any solution for ignoring
additional
fields for the scheme?The text was updated successfully, but these errors were encountered: