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 @@ -727,3 +727,27 @@ function gh13904() {
727
727
}
728
728
) ) ;
729
729
}
730
+
731
+ function gh13957 ( ) {
732
+ class RepositoryBase < T > {
733
+ protected model : mongoose . Model < T > ;
734
+
735
+ constructor ( schemaModel : mongoose . Model < T > ) {
736
+ this . model = schemaModel ;
737
+ }
738
+
739
+ // Testing that the following compiles successfully
740
+ async insertMany ( elems : T [ ] ) : Promise < T [ ] > {
741
+ elems = await this . model . insertMany ( elems ) ;
742
+ return elems ;
743
+ }
744
+ }
745
+
746
+ interface ITest {
747
+ name ?: string
748
+ }
749
+ const schema = new Schema ( { name : String } ) ;
750
+ const TestModel = model ( 'Test' , schema ) ;
751
+ const repository = new RepositoryBase < ITest > ( TestModel ) ;
752
+ expectType < Promise < ITest [ ] > > ( repository . insertMany ( [ { name : 'test' } ] ) ) ;
753
+ }
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