File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -709,3 +709,27 @@ async function gh13746() {
709
709
expectType < ObjectId | undefined > ( findOneAndUpdateRes . lastErrorObject ?. upserted ) ;
710
710
expectType < OkType > ( findOneAndUpdateRes . ok ) ;
711
711
}
712
+
713
+ function gh13957 ( ) {
714
+ class RepositoryBase < T > {
715
+ protected model : mongoose . Model < T > ;
716
+
717
+ constructor ( schemaModel : mongoose . Model < T > ) {
718
+ this . model = schemaModel ;
719
+ }
720
+
721
+ // Testing that the following compiles successfully
722
+ async insertMany ( elems : T [ ] ) : Promise < T [ ] > {
723
+ elems = await this . model . insertMany ( elems ) ;
724
+ return elems ;
725
+ }
726
+ }
727
+
728
+ interface ITest {
729
+ name ?: string
730
+ }
731
+ const schema = new Schema ( { name : String } ) ;
732
+ const TestModel = model ( 'Test' , schema ) ;
733
+ const repository = new RepositoryBase < ITest > ( TestModel ) ;
734
+ expectType < Promise < ITest [ ] > > ( repository . insertMany ( [ { name : 'test' } ] ) ) ;
735
+ }
Original file line number Diff line number Diff line change @@ -362,6 +362,34 @@ declare module 'mongoose' {
362
362
init ( ) : Promise < THydratedDocumentType > ;
363
363
364
364
/** Inserts one or more new documents as a single `insertMany` call to the MongoDB server. */
365
+ insertMany (
366
+ docs : Array < TRawDocType >
367
+ ) : Promise < Array < THydratedDocumentType > > ;
368
+ insertMany (
369
+ docs : Array < TRawDocType > ,
370
+ options : InsertManyOptions & { lean : true ; }
371
+ ) : Promise < Array < Require_id < TRawDocType > > > ;
372
+ insertMany (
373
+ doc : Array < TRawDocType > ,
374
+ options : InsertManyOptions & { ordered : false ; rawResult : true ; }
375
+ ) : Promise < mongodb . InsertManyResult < Require_id < TRawDocType > > & {
376
+ mongoose : {
377
+ validationErrors : Error [ ] ;
378
+ results : Array <
379
+ Error |
380
+ Object |
381
+ THydratedDocumentType
382
+ >
383
+ }
384
+ } > ;
385
+ insertMany (
386
+ docs : Array < TRawDocType > ,
387
+ options : InsertManyOptions & { lean : true , rawResult : true ; }
388
+ ) : Promise < mongodb . InsertManyResult < Require_id < TRawDocType > > > ;
389
+ insertMany (
390
+ docs : Array < TRawDocType > ,
391
+ options : InsertManyOptions & { rawResult : true ; }
392
+ ) : Promise < mongodb . InsertManyResult < Require_id < THydratedDocumentType > > > ;
365
393
insertMany < DocContents = TRawDocType > (
366
394
docs : Array < DocContents | TRawDocType > ,
367
395
options : InsertManyOptions & { lean : true ; }
You can’t perform that action at this time.
0 commit comments