File tree 2 files changed +21
-3
lines changed
2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -325,5 +325,19 @@ function gh11964() {
325
325
/* ... */
326
326
}
327
327
}
328
+ }
328
329
330
+ function gh12091 ( ) {
331
+ interface IUser {
332
+ friendsNames : string [ ] ;
333
+ }
334
+ const userSchema = new Schema < IUser > ( {
335
+ friendsNames : [ String ]
336
+ } ) ;
337
+
338
+ const update : UpdateQuery < IUser > = { $addToSet : { friendsNames : 'John Doe' } } ;
339
+ if ( ! update ?. $addToSet ) {
340
+ return ;
341
+ }
342
+ update . $addToSet . friendsNames = 'Jane Doe' ;
329
343
}
Original file line number Diff line number Diff line change @@ -437,6 +437,10 @@ declare module 'mongoose' {
437
437
438
438
export type SortOrder = - 1 | 1 | 'asc' | 'ascending' | 'desc' | 'descending' ;
439
439
440
+ type Mutable < T > = {
441
+ - readonly [ K in keyof T ] : T [ K ] ;
442
+ }
443
+
440
444
type _UpdateQuery < TSchema > = {
441
445
/** @see https://docs.mongodb.com/manual/reference/operator/update-field/ */
442
446
$currentDate ?: AnyKeys < TSchema > & AnyObject ;
@@ -450,10 +454,10 @@ declare module 'mongoose' {
450
454
$unset ?: AnyKeys < TSchema > & AnyObject ;
451
455
452
456
/** @see https://docs.mongodb.com/manual/reference/operator/update-array/ */
453
- $addToSet ?: mongodb . SetFields < TSchema > ;
457
+ $addToSet ?: Mutable < mongodb . SetFields < TSchema > > ;
454
458
$pop ?: AnyKeys < TSchema > & AnyObject ;
455
- $pull ?: mongodb . PullOperator < TSchema > ;
456
- $push ?: mongodb . PushOperator < TSchema > ;
459
+ $pull ?: Mutable < mongodb . PullOperator < TSchema > > ;
460
+ $push ?: Mutable < mongodb . PushOperator < TSchema > > ;
457
461
$pullAll ?: mongodb . PullAllOperator < TSchema > ;
458
462
459
463
/** @see https://docs.mongodb.com/manual/reference/operator/update-bitwise/ */
You can’t perform that action at this time.
0 commit comments