Skip to content

Commit 7696939

Browse files
committed
loosen $set, $setOnInsert, and $unset to no longer be constrained by type's property values
1 parent c61c24e commit 7696939

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

env.d.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -755,11 +755,16 @@ type MongoQuerySelector<T extends MongoValue> = Partial<
755755

756756
type MongoQuery<T extends MongoObject> = { [K in keyof T]?: T[K] | MongoQuerySelector<T[K]> } & { _id?: MongoId }
757757

758-
type MongoUpdateOperators<T extends MongoObject> = Partial<{
758+
type MongoUpdateArrayOperatorUniversalModifiers<T> = { $each?: T extends [] ? T : T[] }
759+
760+
type MongoUpdateArrayOperatorModifiers<T> = MongoUpdateArrayOperatorUniversalModifiers<T> &
761+
{ $position?: number, $slice?: number, $sort?: 1 | -1 }
762+
763+
type MongoUpdateCommand<T extends MongoObject> = Partial<{
759764
/* Universal operators */
760-
$set: Partial<Record<string, MongoCommandValue> & T>
761-
$setOnInsert: Partial<Record<string, MongoCommandValue> & T>
762-
$unset: Partial<Record<string, ""> & T>
765+
$set: Partial<Record<(string & {}) | keyof T, MongoCommandValue>>
766+
$setOnInsert: Partial<Record<(string & {}) | keyof T, MongoCommandValue>>
767+
$unset: Partial<Record<(string & {}) | keyof T, "">>
763768

764769
$rename: Partial<Record<string, string> & { [key in keyof T]: string }>
765770

@@ -792,13 +797,6 @@ type MongoUpdateOperators<T extends MongoObject> = Partial<{
792797
$pullAll: Record<string, MongoCommandValue> & { [K in keyof T as T[K] extends [] ? K : never]?: T[K] }
793798
}>
794799

795-
type MongoUpdateArrayOperatorUniversalModifiers<T> = { $each?: T extends [] ? T : T[] }
796-
797-
type MongoUpdateArrayOperatorModifiers<T> = MongoUpdateArrayOperatorUniversalModifiers<T> &
798-
{ $position?: number, $slice?: number, $sort?: 1 | -1 }
799-
800-
type MongoUpdateCommand<Schema extends MongoObject> = MongoUpdateOperators<Schema>
801-
802800
type SortOrder = { [key: string]: 1 | -1 | SortOrder }
803801

804802
type Cursor<T> = {

0 commit comments

Comments
 (0)