Closed
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Mongoose version
8.16.1
Node.js version
v22.15.0
MongoDB server version
8.0.10
Typescript version (if applicable)
5.8.3
Description
The Schema.virtual()
method calculates a new HydratedDocument
type instead of using THydratedDocumentType
. This makes it impossible to use Schema.virtual()
with a custom THydratedDocumentType
as the types don't line up.
Steps to Reproduce
Make a new type:
type RawType = /** some type */;
type ModelType = /** some model type */;
type DocType = /** some document type */;
const schema = new mongoose.Schema<
RawType,
ModelType,
any,
any,
any,
any,
GetSchemaOptions<RawType>,
any,
DocType
>();
Trying to call the virtual
method will then result in it returning VirtualType<any>
, not VirtualType<DocType>
.
Expected Behavior
Calling Schema.virtual()
should return VirtualType<THydratedDocumentType>
by default.