File tree 2 files changed +48
-4
lines changed
2 files changed +48
-4
lines changed Original file line number Diff line number Diff line change @@ -352,6 +352,50 @@ async function gh12277() {
352
352
] ) ;
353
353
}
354
354
355
+ async function overwriteBulkWriteContents ( ) {
356
+ type DocumentType < T > = Document < any , any , T > & T ;
357
+
358
+ interface BaseModelClassDoc {
359
+ firstname : string ;
360
+ }
361
+
362
+ const baseModelClassSchema = new Schema ( {
363
+ firstname : String
364
+ } ) ;
365
+
366
+ const BaseModel = model < BaseModelClassDoc > ( 'test' , baseModelClassSchema ) ;
367
+
368
+ expectError ( BaseModel . bulkWrite < { testy : string } > ( [
369
+ {
370
+ insertOne : {
371
+ document : {
372
+ test : 'hello'
373
+ }
374
+ }
375
+ }
376
+ ] ) ) ;
377
+
378
+ BaseModel . bulkWrite < { testy : string } > ( [
379
+ {
380
+ insertOne : {
381
+ document : {
382
+ testy : 'hello'
383
+ }
384
+ }
385
+ }
386
+ ] ) ;
387
+
388
+ BaseModel . bulkWrite ( [
389
+ {
390
+ insertOne : {
391
+ document : {
392
+ randomPropertyNotInTypes : 'hello'
393
+ }
394
+ }
395
+ }
396
+ ] ) ;
397
+ }
398
+
355
399
export function autoTypedModel ( ) {
356
400
const AutoTypedSchema = autoTypedSchema ( ) ;
357
401
const AutoTypedModel = model ( 'AutoTypeModel' , AutoTypedSchema ) ;
Original file line number Diff line number Diff line change @@ -162,12 +162,12 @@ declare module 'mongoose' {
162
162
* if you use `create()`) because with `bulkWrite()` there is only one network
163
163
* round trip to the MongoDB server.
164
164
*/
165
- bulkWrite (
166
- writes : Array < mongodb . AnyBulkWriteOperation < T extends Document ? any : ( T extends { } ? T : any ) > > ,
165
+ bulkWrite < DocContents = T > (
166
+ writes : Array < mongodb . AnyBulkWriteOperation < DocContents extends Document ? any : ( DocContents extends { } ? DocContents : any ) > > ,
167
167
options : mongodb . BulkWriteOptions & MongooseBulkWriteOptions & { ordered : false }
168
168
) : Promise < mongodb . BulkWriteResult & { mongoose ?: { validationErrors : Error [ ] } } > ;
169
- bulkWrite (
170
- writes : Array < mongodb . AnyBulkWriteOperation < T extends Document ? any : ( T extends { } ? T : any ) > > ,
169
+ bulkWrite < DocContents = T > (
170
+ writes : Array < mongodb . AnyBulkWriteOperation < DocContents extends Document ? any : ( DocContents extends { } ? DocContents : any ) > > ,
171
171
options ?: mongodb . BulkWriteOptions & MongooseBulkWriteOptions
172
172
) : Promise < mongodb . BulkWriteResult > ;
173
173
You can’t perform that action at this time.
0 commit comments