Skip to content

Commit b7a63de

Browse files
authored
Merge pull request #14088 from Automattic/vkarpov15/gh-14003
types(model): support calling `Model.validate()` with `pathsToSkip` option
2 parents 9224614 + 6ee82c1 commit b7a63de

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

test/types/models.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,3 +758,11 @@ function gh13957() {
758758
const repository = new RepositoryBase<ITest>(TestModel);
759759
expectType<Promise<ITest[]>>(repository.insertMany([{ name: 'test' }]));
760760
}
761+
762+
async function gh14003() {
763+
const schema = new Schema({ name: String });
764+
const TestModel = model('Test', schema);
765+
766+
await TestModel.validate({ name: 'foo' }, ['name']);
767+
await TestModel.validate({ name: 'foo' }, { pathsToSkip: ['name'] });
768+
}

types/models.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,9 @@ declare module 'mongoose' {
461461

462462
/** Casts and validates the given object against this model's schema, passing the given `context` to custom validators. */
463463
validate(): Promise<void>;
464-
validate(optional: any): Promise<void>;
465-
validate(optional: any, pathsToValidate: PathsToValidate): Promise<void>;
464+
validate(obj: any): Promise<void>;
465+
validate(obj: any, pathsOrOptions: PathsToValidate): Promise<void>;
466+
validate(obj: any, pathsOrOptions: { pathsToSkip?: pathsToSkip }): Promise<void>;
466467

467468
/** Watches the underlying collection for changes using [MongoDB change streams](https://www.mongodb.com/docs/manual/changeStreams/). */
468469
watch<ResultType extends mongodb.Document = any, ChangeType extends mongodb.ChangeStreamDocument = any>(pipeline?: Array<Record<string, unknown>>, options?: mongodb.ChangeStreamOptions & { hydrate?: boolean }): mongodb.ChangeStream<ResultType, ChangeType>;

0 commit comments

Comments
 (0)