Discriminated schemas nested with discriminated schemas don't instantiate the correct types #13898
Closed
2 tasks done
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Prerequisites
Mongoose version
7.5.3
Node.js version
18.16
MongoDB server version
6.0.5
Typescript version (if applicable)
No response
Description
When defining a discriminated schema A that has a field which is discriminated schema B, after applying the discriminators at the schema level and instantiating an object of schema A, the types of B within it will always be of the default base type.
If you apply the discriminators for schema B directly on the path, it works as expected. This issue also happens if schema A has a subtype that self-references A. I am not sure how easy it is to convery through text, but I hope the code example makes it clear!
Steps to Reproduce
Expected Behavior
Shown in the code example, once discriminators are applied to a schema, the discriminators should always run wherever the schema is.
The text was updated successfully, but these errors were encountered: