@@ -2536,40 +2536,29 @@ declare module 'mongoose' {
2536
2536
2537
2537
type NumericTypes = number | mongodb . Decimal128 | mongodb . Double | mongodb . Int32 | mongodb . Long ;
2538
2538
2539
- type KeysOfAType < TSchema , Type > = {
2540
- [ key in keyof TSchema ] : NonNullable < TSchema [ key ] > extends Type ? key : never ;
2541
- } [ keyof TSchema ] ;
2542
-
2543
- type PullOperator < TSchema > = {
2544
- [ key in KeysOfAType < TSchema , ReadonlyArray < any > > ] ?:
2545
- | Partial < Unpacked < TSchema [ key ] > >
2546
- | mongodb . ObjectQuerySelector < Unpacked < TSchema [ key ] > >
2547
- // Doesn't look like TypeScript has good support for creating an
2548
- // object containing dotted keys:
2549
- // https://stackoverflow.com/questions/58434389/typescript-deep-keyof-of-a-nested-object
2550
- | mongodb . QuerySelector < any >
2551
- | any ;
2552
- } | any ; // Because TS doesn't have good support for creating an object with dotted keys, including `.$.` re: #10075
2539
+ type OnlyFieldsOfType < TSchema , FieldType = any , AssignableType = FieldType > = {
2540
+ [ key in keyof TSchema ] ?: [ Extract < TSchema [ key ] , FieldType > ] extends [ never ] ? never : AssignableType ;
2541
+ } ;
2553
2542
2554
2543
/** @see https://docs.mongodb.com/manual/reference/operator/update */
2555
2544
type _UpdateQuery < TSchema > = {
2556
2545
/** @see https://docs.mongodb.com/manual/reference/operator/update-field/ */
2557
- $currentDate ?: mongodb . OnlyFieldsOfType < TSchema , NativeDate | mongodb . Timestamp , true | { $type : 'date' | 'timestamp' } > | any ;
2558
- $inc ?: mongodb . OnlyFieldsOfType < TSchema , NumericTypes | undefined > | any ;
2559
- $min ?: mongodb . MatchKeysAndValues < TSchema > ;
2560
- $max ?: mongodb . MatchKeysAndValues < TSchema > ;
2561
- $mul ?: mongodb . OnlyFieldsOfType < TSchema , NumericTypes | undefined > | any ;
2546
+ $currentDate ?: OnlyFieldsOfType < TSchema , NativeDate , true | { $type : 'date' | 'timestamp' } > & AnyObject ;
2547
+ $inc ?: OnlyFieldsOfType < TSchema , NumericTypes | undefined > & AnyObject ;
2548
+ $min ?: OnlyFieldsOfType < TSchema , any , any > & AnyObject ;
2549
+ $max ?: OnlyFieldsOfType < TSchema , any , any > & AnyObject ;
2550
+ $mul ?: OnlyFieldsOfType < TSchema , NumericTypes | undefined > & AnyObject ;
2562
2551
$rename ?: { [ key : string ] : string } ;
2563
- $set ?: mongodb . MatchKeysAndValues < TSchema > ;
2564
- $setOnInsert ?: mongodb . MatchKeysAndValues < TSchema > ;
2565
- $unset ?: mongodb . OnlyFieldsOfType < TSchema , any , any > | any ;
2552
+ $set ?: OnlyFieldsOfType < TSchema , any , any > & AnyObject ;
2553
+ $setOnInsert ?: OnlyFieldsOfType < TSchema , any , any > & AnyObject ;
2554
+ $unset ?: OnlyFieldsOfType < TSchema , any , any > & AnyObject ;
2566
2555
2567
2556
/** @see https://docs.mongodb.com/manual/reference/operator/update-array/ */
2568
- $addToSet ?: mongodb . SetFields < TSchema > | any ;
2569
- $pop ?: mongodb . OnlyFieldsOfType < TSchema , ReadonlyArray < any > , 1 | - 1 > | any ;
2570
- $pull ?: PullOperator < TSchema > ;
2571
- $push ?: mongodb . PushOperator < TSchema > | any ;
2572
- $pullAll ?: mongodb . PullAllOperator < TSchema > | any ;
2557
+ $addToSet ?: OnlyFieldsOfType < TSchema , any [ ] , any > & AnyObject ;
2558
+ $pop ?: OnlyFieldsOfType < TSchema , ReadonlyArray < any > , 1 | - 1 > & AnyObject ;
2559
+ $pull ?: OnlyFieldsOfType < TSchema , ReadonlyArray < any > , any > & AnyObject ;
2560
+ $push ?: OnlyFieldsOfType < TSchema , ReadonlyArray < any > , any > & AnyObject ;
2561
+ $pullAll ?: OnlyFieldsOfType < TSchema , ReadonlyArray < any > , any > & AnyObject ;
2573
2562
2574
2563
/** @see https://docs.mongodb.com/manual/reference/operator/update-bitwise/ */
2575
2564
$bit ?: {
@@ -2585,7 +2574,18 @@ declare module 'mongoose' {
2585
2574
{ $replaceRoot : any } |
2586
2575
{ $replaceWith : any } ;
2587
2576
2588
- export type UpdateQuery < T > = ( _UpdateQuery < DocumentDefinition < T > > & mongodb . MatchKeysAndValues < DocumentDefinition < T > > ) ;
2577
+ type __UpdateDefProperty < T > =
2578
+ 0 extends ( 1 & T ) ? T : // any
2579
+ T extends unknown [ ] ? LeanArray < T > : // Array
2580
+ T extends Document ? LeanDocument < T > : // Subdocument
2581
+ [ Extract < T , mongodb . ObjectId > ] extends [ never ] ? T :
2582
+ T | string ;
2583
+ type __UpdateQueryDef < T > = {
2584
+ [ K in keyof T ] : __UpdateDefProperty < T [ K ] > ;
2585
+ } ;
2586
+ type _UpdateQueryDef < T > = __UpdateQueryDef < T > ;
2587
+
2588
+ export type UpdateQuery < T > = ( _UpdateQuery < _UpdateQueryDef < T > > & mongodb . MatchKeysAndValues < _UpdateQueryDef < LeanDocument < T > > > ) ;
2589
2589
2590
2590
type _AllowStringsForIds < T > = {
2591
2591
[ K in keyof T ] : [ Extract < T [ K ] , mongodb . ObjectId > ] extends [ never ]
0 commit comments