Skip to content

Commit c1905c1

Browse files
committed
types(query): add missing runValidators back to MongooseQueryOptions
Fix #14275
1 parent ebf7d07 commit c1905c1

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

test/types/queries.test.ts

+26
Original file line numberDiff line numberDiff line change
@@ -544,3 +544,29 @@ function gh14190() {
544544
ModifyResult<ReturnType<(typeof UserModel)['hydrate']>>
545545
>(res2);
546546
}
547+
548+
function mongooseQueryOptions() {
549+
const userSchema = new Schema({ name: String, age: Number });
550+
const UserModel = model('User', userSchema);
551+
552+
UserModel.updateOne(
553+
{ name: 'bar' },
554+
{ name: 'baz' },
555+
{
556+
multipleCastError: true,
557+
overwriteDiscriminatorKey: true,
558+
runValidators: true,
559+
sanitizeProjection: true,
560+
sanitizeFilter: true,
561+
strict: true,
562+
strictQuery: 'throw',
563+
timestamps: false,
564+
translateAliases: false
565+
}
566+
);
567+
568+
UserModel.findOne({}, null, {
569+
lean: true,
570+
populate: 'test'
571+
});
572+
}

types/query.d.ts

+13-7
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,19 @@ declare module 'mongoose' {
1717
*/
1818
type FilterQuery<T> = _FilterQuery<T>;
1919

20-
type MongooseQueryOptions<DocType = unknown> = Pick<QueryOptions<DocType>, 'populate' |
21-
'lean' |
22-
'strict' |
23-
'sanitizeProjection' |
24-
'sanitizeFilter' |
25-
'timestamps' |
26-
'translateAliases'
20+
type MongooseQueryOptions<DocType = unknown> = Pick<
21+
QueryOptions<DocType>,
22+
'lean' |
23+
'multipleCastError' |
24+
'overwriteDiscriminatorKey' |
25+
'populate' |
26+
'runValidators' |
27+
'sanitizeProjection' |
28+
'sanitizeFilter' |
29+
'strict' |
30+
'strictQuery' |
31+
'timestamps' |
32+
'translateAliases'
2733
>;
2834

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

0 commit comments

Comments
 (0)