Skip to content

Commit

Permalink
perf(types): make a couple of micro-optimizations to speed up #10349
Browse files Browse the repository at this point in the history
…benchmark
  • Loading branch information
vkarpov15 committed Aug 12, 2022
1 parent 53ea180 commit 339adb6
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,10 +452,6 @@ declare module 'mongoose' {

export type SortOrder = -1 | 1 | 'asc' | 'ascending' | 'desc' | 'descending';

type Mutable<T> = {
-readonly [K in keyof T]: T[K];
};

type _UpdateQuery<TSchema> = {
/** @see https://docs.mongodb.com/manual/reference/operator/update-field/ */
$currentDate?: AnyKeys<TSchema> & AnyObject;
Expand All @@ -469,7 +465,7 @@ declare module 'mongoose' {
$unset?: AnyKeys<TSchema> & AnyObject;

/** @see https://docs.mongodb.com/manual/reference/operator/update-array/ */
$addToSet?: Mutable<mongodb.SetFields<TSchema>>;
$addToSet?: AnyKeys<TSchema> & AnyObject;
$pop?: AnyKeys<TSchema> & AnyObject;
$pull?: AnyKeys<TSchema> & AnyObject;
$push?: AnyKeys<TSchema> & AnyObject;
Expand All @@ -487,21 +483,14 @@ declare module 'mongoose' {
{ $replaceRoot: any } |
{ $replaceWith: any };

export type __UpdateDefProperty<T> =
[Extract<T, mongodb.ObjectId>] extends [never] ? T :
T | string;
export type _UpdateQueryDef<T> = {
[K in keyof T]?: __UpdateDefProperty<T[K]>;
};

/**
* Update query command to perform on the document
* @example
* ```js
* { age: 30 }
* ```
*/
export type UpdateQuery<T> = _UpdateQuery<_UpdateQueryDef<T>> & AnyObject;
export type UpdateQuery<T> = _UpdateQuery<T> & AnyObject;

export type DocumentDefinition<T> = {
[K in keyof Omit<T, Exclude<keyof Document, '_id' | 'id' | '__v'>>]:
Expand Down

0 comments on commit 339adb6

Please sign in to comment.