-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Allow partial (subset) type matching #392
Comments
This seems strange to me. The way this API is modeled just seems incorrect. |
Hi Dan, Thanks for the feedback. I feel like there may be some confusion on what this suggestion is trying to accomplish. If I could take your points one by one.
That's absolutely correct. According to the Backbone documentation, "a hash of attributes (one or many) on the model", which precisely aligns with the intent of this suggestion.
I don't think in my proposal the API for Person is incorrect. If I'm constructing a new instance of Person then I want
In no case that I've described would I be assigning
I'm not sure I understand. This proposal is to avoid adding duplicate type definitions. Consider:
Now, as a user of Backbone, I can simply define
To be clear: the pain is not in the implementation of Understood if this remains closed but wanted to make sure the proposal was well understood. |
A small correction: regarding compile-time checks, I realize this proposal by itself won't fix that. However, it does make it so that I do not need to make every property on my models optional in order to support partial updates as I currently do. |
+1 |
+1 This would make mongo projections in TS much safer. |
This should be reopened. This is a thing. |
@BowserKingKoopa I think this is essentially reopened in #4889. I would track there. |
Various libraries have a concept of applying partial updates to an object. For example:
http://backbonejs.org/#Model-set
http://facebook.github.io/react/docs/component-api.html#setstate
Take the following example (to roughly mimic Backbone)
In this case an error is thrown saying that properties are missing. One solution is to make all of the properties in the interface optional. However, that may not be desirable; I may actually want those properties to be required in other locations and only optional in this specific context. I would like to propose a feature where in a certain context a new type is created on-the-fly based on another type where all properties of the base type are optional. For example:
and therefore the following would work:
I think this would also work particularly well in conjunction with my other suggestion #391
Where zero or more properties from Person will match but ONLY properties from Person will match.
The text was updated successfully, but these errors were encountered: