-
Notifications
You must be signed in to change notification settings - Fork 8
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
Clarify the specs regarding extra properties in objects passed to fromJS() #24
Comments
Update :-) The auto-generated code in the type BarFromJSType = $Shape<BarFullType> & BarRequiredArguments; However, why not simply use the following instead ? type BarFromJSType = $Shape<BarModelType> & BarRequiredArguments; It seems to help flow better at showing where the error actually is. |
What are your default values in this case? I'm curious why |
export type BarModelType = {
barStr: string,
barNum: number,
};
export const defaultBarValues: BarModelType = {
barStr: 'foo',
barNum: 3,
}
const b = Bar.fromJS({
a: "mklj",
}) Using: type BarFromJSType = $Shape<BarFullType> & BarRequiredArguments; Flow yields:
Which is quite complicated and confuses both Webstorm and Sublime with Flow linter. As opposed to using: type BarFromJSType = $Shape<BarModelType> & BarRequiredArguments; ... where Flow just yields:
... which is way simpler and makes IDEs happy ! |
Thanks for the detailed writeup. I'm going to be out the rest of the week, but will try to get this fixed next week. |
When we instantiate a model, it's critical to make sure not to use properties that are not part of the model type, especially because it can be the result of a typo.
For example, given the definition:
This should yield an error:
because
barstr
!==barStr
.It's not clear whether the library is supposed to allow Flow to detect these errors.
Currently, sometimes it does not, and sometimes is does but it seems to be a side effect of the use of
$Shape<>
in some condition (when default properties are defined).I'm not 100% sure about this, but I think this requirement (no extra properties) could be precisely enforced by prepending
$Shape<BarModelType> & ...
to thejson
parameter of thefromJS()
. method.The text was updated successfully, but these errors were encountered: