Skip to content

Commit

Permalink
Merge pull request #14278 from Automattic/vkarpov15/gh-14275
Browse files Browse the repository at this point in the history
types(query): add missing `runValidators` back to MongooseQueryOptions
  • Loading branch information
vkarpov15 committed Jan 22, 2024
2 parents ebf7d07 + c1905c1 commit 8265b2e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
26 changes: 26 additions & 0 deletions test/types/queries.test.ts
Expand Up @@ -544,3 +544,29 @@ function gh14190() {
ModifyResult<ReturnType<(typeof UserModel)['hydrate']>>
>(res2);
}

function mongooseQueryOptions() {
const userSchema = new Schema({ name: String, age: Number });
const UserModel = model('User', userSchema);

UserModel.updateOne(
{ name: 'bar' },
{ name: 'baz' },
{
multipleCastError: true,
overwriteDiscriminatorKey: true,
runValidators: true,
sanitizeProjection: true,
sanitizeFilter: true,
strict: true,
strictQuery: 'throw',
timestamps: false,
translateAliases: false
}
);

UserModel.findOne({}, null, {
lean: true,
populate: 'test'
});
}
20 changes: 13 additions & 7 deletions types/query.d.ts
Expand Up @@ -17,13 +17,19 @@ declare module 'mongoose' {
*/
type FilterQuery<T> = _FilterQuery<T>;

type MongooseQueryOptions<DocType = unknown> = Pick<QueryOptions<DocType>, 'populate' |
'lean' |
'strict' |
'sanitizeProjection' |
'sanitizeFilter' |
'timestamps' |
'translateAliases'
type MongooseQueryOptions<DocType = unknown> = Pick<
QueryOptions<DocType>,
'lean' |
'multipleCastError' |
'overwriteDiscriminatorKey' |
'populate' |
'runValidators' |
'sanitizeProjection' |
'sanitizeFilter' |
'strict' |
'strictQuery' |
'timestamps' |
'translateAliases'
>;

type ProjectionFields<DocType> = { [Key in keyof DocType]?: any } & Record<string, any>;
Expand Down

0 comments on commit 8265b2e

Please sign in to comment.