@@ -439,3 +439,66 @@ export async function testPushWithId(): Promise<void> {
439
439
collectionWithSchema . updateMany ( { } , { } )
440
440
) ;
441
441
}
442
+
443
+ {
444
+ // NODE-5647 - Type error with $addToSet in bulkWrite
445
+ interface TestDocument {
446
+ readonly myId : number ;
447
+ readonly mySet : number [ ] ;
448
+ readonly myAny : any ;
449
+ }
450
+ const collection = undefined as unknown as Collection < TestDocument > ;
451
+ expectError ( collection . updateOne ( { myId : 0 } , { $addToSet : { mySet : 'value of other type' } } ) ) ;
452
+ collection . updateOne ( { myId : 0 } , { $addToSet : { mySet : 0 } } ) ;
453
+ collection . updateOne ( { myId : 0 } , { $addToSet : { myAny : 1 } } ) ;
454
+ collection . updateOne ( { myId : 0 } , [
455
+ {
456
+ $addToSet : { mySet : 0 }
457
+ }
458
+ ] ) ;
459
+ expectError ( collection . updateMany ( { myId : 0 } , { $addToSet : { mySet : 'value of other type' } } ) ) ;
460
+ collection . updateMany ( { myId : 0 } , { $addToSet : { mySet : 0 } } ) ;
461
+ collection . updateMany ( { myId : 0 } , { $addToSet : { myAny : 1 } } ) ;
462
+ collection . updateMany ( { myId : 0 } , [
463
+ {
464
+ $addToSet : { mySet : 0 }
465
+ }
466
+ ] ) ;
467
+
468
+ interface IndexSingatureTestDocument extends Document {
469
+ readonly myId : number ;
470
+ readonly mySet : number [ ] ;
471
+ readonly myAny : any ;
472
+ }
473
+ const indexSingatureCollection = undefined as unknown as Collection < IndexSingatureTestDocument > ;
474
+ indexSingatureCollection . updateOne ( { myId : 0 } , { $addToSet : { mySet : 0 } } ) ;
475
+ indexSingatureCollection . updateOne ( { myId : 0 } , { $addToSet : { myAny : 1 } } ) ;
476
+ indexSingatureCollection . updateOne ( { myId : 0 } , [
477
+ {
478
+ $addToSet : { mySet : 0 }
479
+ }
480
+ ] ) ;
481
+ indexSingatureCollection . updateMany ( { myId : 0 } , { $addToSet : { mySet : 0 } } ) ;
482
+ indexSingatureCollection . updateMany ( { myId : 0 } , { $addToSet : { myAny : 1 } } ) ;
483
+ indexSingatureCollection . updateMany ( { myId : 0 } , [
484
+ {
485
+ $addToSet : { mySet : 0 }
486
+ }
487
+ ] ) ;
488
+
489
+ const collectionOfAnyType = undefined as unknown as Collection < any > ;
490
+ collectionOfAnyType . updateOne ( { myId : 0 } , { $addToSet : { mySet : 0 } } ) ;
491
+ collectionOfAnyType . updateOne ( { myId : 0 } , { $addToSet : { myAny : 1 } } ) ;
492
+ collectionOfAnyType . updateOne ( { myId : 0 } , [
493
+ {
494
+ $addToSet : { mySet : 0 }
495
+ }
496
+ ] ) ;
497
+ collectionOfAnyType . updateMany ( { myId : 0 } , { $addToSet : { mySet : 0 } } ) ;
498
+ collectionOfAnyType . updateMany ( { myId : 0 } , { $addToSet : { myAny : 1 } } ) ;
499
+ collectionOfAnyType . updateMany ( { myId : 0 } , [
500
+ {
501
+ $addToSet : { mySet : 0 }
502
+ }
503
+ ] ) ;
504
+ }
0 commit comments