-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Automatic model casting with union types #24
Comments
Thanks for the report. The problem comes from User being optional, which is the equivalent of a union type [User, undefined] and makes automatic model casting ambiguous here. I'll try to make automatic model casting working with union types as well, and keep you updated. |
Current proposal as exposed in #25
When the property is defined by an union type containing several models, the library checks for each model if the object does validate its definition. If there is only one model that does the match, it is pretty straightforward and we can return an instance of this model. When there are several suitable models, the libary does nothing and return the object as it is, with a console warning "Ambiguous model for value X, could be Model A or B or C...." I let this open for discussion and tests for a few days, then it will be released as v2.2 |
A few changes to the proposal:
This issue is fixed in v2.2 |
After assignment a plain object to a dynamic property that property becomes typeless (in the example below I expect to get User instance but got an Object):
The text was updated successfully, but these errors were encountered: