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
fix: Discriminator generic type not being passed to schema #11898
fix: Discriminator generic type not being passed to schema #11898
Conversation
-- Fix instance created from model returned from discriminator having type 'any' -- Fix model created from discriminator not inheriting the properties from the base model
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests are failing because you also need to modify types/schematypes.d.ts
, there's a couple places in that file where we use AcceptsDiscriminator
:
mongoose/types/schematypes.d.ts
Line 272 in 4cf2920
class Array extends SchemaType implements AcceptsDiscriminator { |
-- Fix model type returned from discriminator ignoring possible parent schema property overrides
…or as generic -- Fix some of the classes in the Schema namespace that were not updated to use AcceptsDiscriminator as a generic -- Those classes were updated to be generics with default type to any, so no change in behavior is expected
…hat implements AcceptsDiscriminatos
I've updated the classes in Their 'B' type is passed to It defaults to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 👍
In hindsight, I think I'm going to have to revert this PR. This really slows down our TS performance benchmark. Before:
After:
|
Well, it does make sense that performance would slow down a little since the types were being defaulted to any and with this PR some generics were added for the types to be passed down It is a new "feature", per se, it make sense for it to impact something |
-- Fix instance created from model returned from discriminator having type 'any'
-- Fix model created from discriminator not inheriting the properties from the base model
Summary
A model created from a discriminator does not have types for the "document" (save, find, etc) as the original model does and does not inherit the properties from the base model
Examples
This is a remake of #11897 with fixed branch name and commits