@@ -205,6 +205,18 @@ declare module 'mongoose' {
205205 ? ( ResultType extends any [ ] ? Require_id < FlattenMaps < RawDocType > > [ ] : Require_id < FlattenMaps < RawDocType > > )
206206 : ResultType ;
207207
208+ type MergePopulatePaths < RawDocType , ResultType , QueryOp , Paths , TQueryHelpers > = QueryOp extends QueryOpThatReturnsDocument
209+ ? ResultType extends null
210+ ? ResultType
211+ : ResultType extends ( infer U ) [ ]
212+ ? U extends Document
213+ ? HydratedDocument < MergeType < RawDocType , Paths > , Record < string , never > , TQueryHelpers > [ ]
214+ : ( MergeType < U , Paths > ) [ ]
215+ : ResultType extends Document
216+ ? HydratedDocument < MergeType < RawDocType , Paths > , Record < string , never > , TQueryHelpers >
217+ : MergeType < ResultType , Paths >
218+ : MergeType < ResultType , Paths > ;
219+
208220 class Query < ResultType , DocType , THelpers = { } , RawDocType = DocType , QueryOp = 'find' > implements SessionOperation {
209221 _mongooseOptions : MongooseQueryOptions < DocType > ;
210222
@@ -602,22 +614,43 @@ declare module 'mongoose' {
602614 polygon ( ...coordinatePairs : number [ ] [ ] ) : this;
603615
604616 /** Specifies paths which should be populated with other documents. */
605- populate < Paths = { } > (
617+ populate (
618+ path : string | string [ ] ,
619+ select ?: string | any ,
620+ model ?: string | Model < any , THelpers > ,
621+ match ?: any
622+ ) : QueryWithHelpers <
623+ ResultType ,
624+ DocType ,
625+ THelpers ,
626+ RawDocType ,
627+ QueryOp
628+ > ;
629+ populate (
630+ options : PopulateOptions | ( PopulateOptions | string ) [ ]
631+ ) : QueryWithHelpers <
632+ ResultType ,
633+ DocType ,
634+ THelpers ,
635+ RawDocType ,
636+ QueryOp
637+ > ;
638+ populate < Paths > (
606639 path : string | string [ ] ,
607640 select ?: string | any ,
608641 model ?: string | Model < any , THelpers > ,
609642 match ?: any
610643 ) : QueryWithHelpers <
611- UnpackedIntersection < ResultType , Paths > ,
644+ MergePopulatePaths < RawDocType , ResultType , QueryOp , Paths , THelpers > ,
612645 DocType ,
613646 THelpers ,
614647 UnpackedIntersection < RawDocType , Paths > ,
615648 QueryOp
616649 > ;
617- populate < Paths = { } > (
650+ populate < Paths > (
618651 options : PopulateOptions | ( PopulateOptions | string ) [ ]
619652 ) : QueryWithHelpers <
620- UnpackedIntersection < ResultType , Paths > ,
653+ MergePopulatePaths < RawDocType , ResultType , QueryOp , Paths , THelpers > ,
621654 DocType ,
622655 THelpers ,
623656 UnpackedIntersection < RawDocType , Paths > ,
0 commit comments