diff --git a/types/index.d.ts b/types/index.d.ts index bbaa4f66901..02c975a4eb3 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -157,8 +157,37 @@ declare module 'mongoose' { > > >; - export type HydratedSingleSubdocument = Types.Subdocument, DocType> & Require_id & TOverrides; - export type HydratedArraySubdocument = Types.ArraySubdocument, DocType> & Require_id & TOverrides; + export type HydratedSingleSubdocument< + DocType, + TOverrides = {} + > = IfAny< + DocType, + any, + TOverrides extends Record ? + Types.Subdocument, DocType> & Require_id : + IfAny< + TOverrides, + Types.Subdocument, DocType> & Require_id, + Types.Subdocument, DocType> & MergeType< + Require_id, + TOverrides + > + > + >; + export type HydratedArraySubdocument = IfAny< + DocType, + any, + TOverrides extends Record ? + Types.ArraySubdocument, DocType> & Require_id : + IfAny< + TOverrides, + Types.ArraySubdocument, DocType> & Require_id, + Types.ArraySubdocument, DocType> & MergeType< + Require_id, + TOverrides + > + > + >; export type HydratedDocumentFromSchema = HydratedDocument< InferSchemaType,