From fdb8565a2f6df169801e93cc07990eb0ffd2bc09 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Sun, 6 Mar 2022 02:38:55 +0100 Subject: [PATCH 1/2] extract document type --- types/document.d.ts | 244 ++++++++++++++++++++++++++++++++++++++++++++ types/index.d.ts | 240 +------------------------------------------ 2 files changed, 245 insertions(+), 239 deletions(-) create mode 100644 types/document.d.ts diff --git a/types/document.d.ts b/types/document.d.ts new file mode 100644 index 00000000000..b6530f548b0 --- /dev/null +++ b/types/document.d.ts @@ -0,0 +1,244 @@ +import mongodb = require('mongodb'); + +declare module 'mongoose' { + + /** A list of paths to skip. If set, Mongoose will validate every modified path that is not in this list. */ + type pathsToSkip = string[] | string; + + class Document { + constructor(doc?: any); + + /** This documents _id. */ + _id?: T; + + /** This documents __v. */ + __v?: any; + + /* Get all subdocs (by bfs) */ + $getAllSubdocs(): Document[]; + + /** Don't run validation on this path or persist changes to this path. */ + $ignore(path: string): void; + + /** Checks if a path is set to its default. */ + $isDefault(path: string): boolean; + + /** Getter/setter, determines whether the document was removed or not. */ + $isDeleted(val?: boolean): boolean; + + /** Returns an array of all populated documents associated with the query */ + $getPopulatedDocs(): Document[]; + + /** + * Returns true if the given path is nullish or only contains empty objects. + * Useful for determining whether this subdoc will get stripped out by the + * [minimize option](/docs/guide.html#minimize). + */ + $isEmpty(path: string): boolean; + + /** Checks if a path is invalid */ + $isValid(path: string): boolean; + + /** + * Empty object that you can use for storing properties on the document. This + * is handy for passing data to middleware without conflicting with Mongoose + * internals. + */ + $locals: Record; + + /** Marks a path as valid, removing existing validation errors. */ + $markValid(path: string): void; + + /** + * A string containing the current operation that Mongoose is executing + * on this document. May be `null`, `'save'`, `'validate'`, or `'remove'`. + */ + $op: string | null; + + /** + * Getter/setter around the session associated with this document. Used to + * automatically set `session` if you `save()` a doc that you got from a + * query with an associated session. + */ + $session(session?: mongodb.ClientSession | null): mongodb.ClientSession; + + /** Alias for `set()`, used internally to avoid conflicts */ + $set(path: string, val: any, options?: any): this; + $set(path: string, val: any, type: any, options?: any): this; + $set(value: any): this; + + /** Set this property to add additional query filters when Mongoose saves this document and `isNew` is false. */ + $where: Record; + + /** If this is a discriminator model, `baseModelName` is the name of the base model. */ + baseModelName?: string; + + /** Collection the model uses. */ + collection: Collection; + + /** Connection the model uses. */ + db: Connection; + + /** Removes this document from the db. */ + delete(options?: QueryOptions): QueryWithHelpers; + delete(options: QueryOptions, cb?: Callback): void; + delete(cb: Callback): void; + + /** Removes this document from the db. */ + deleteOne(options?: QueryOptions): QueryWithHelpers; + deleteOne(options: QueryOptions, cb?: Callback): void; + deleteOne(cb: Callback): void; + + /** + * Takes a populated field and returns it to its unpopulated state. If called with + * no arguments, then all populated fields are returned to their unpopulated state. + */ + depopulate(path?: string | string[]): this; + + /** + * Returns the list of paths that have been directly modified. A direct + * modified path is a path that you explicitly set, whether via `doc.foo = 'bar'`, + * `Object.assign(doc, { foo: 'bar' })`, or `doc.set('foo', 'bar')`. + */ + directModifiedPaths(): Array; + + /** + * Returns true if this document is equal to another document. + * + * Documents are considered equal when they have matching `_id`s, unless neither + * document has an `_id`, in which case this function falls back to using + * `deepEqual()`. + */ + equals(doc: Document): boolean; + + /** Hash containing current validation errors. */ + errors?: Error.ValidationError; + + /** Returns the value of a path. */ + get(path: string, type?: any, options?: any): any; + + /** + * Returns the changes that happened to the document + * in the format that will be sent to MongoDB. + */ + getChanges(): UpdateQuery; + + /** The string version of this documents _id. */ + id?: any; + + /** Signal that we desire an increment of this documents version. */ + increment(): this; + + /** + * Initializes the document without setters or marking anything modified. + * Called internally after a document is returned from mongodb. Normally, + * you do **not** need to call this function on your own. + */ + init(obj: any, opts?: any, cb?: Callback): this; + + /** Marks a path as invalid, causing validation to fail. */ + invalidate(path: string, errorMsg: string | NativeError, value?: any, kind?: string): NativeError | null; + + /** Returns true if `path` was directly set and modified, else false. */ + isDirectModified(path: string): boolean; + + /** Checks if `path` was explicitly selected. If no projection, always returns true. */ + isDirectSelected(path: string): boolean; + + /** Checks if `path` is in the `init` state, that is, it was set by `Document#init()` and not modified since. */ + isInit(path: string): boolean; + + /** + * Returns true if any of the given paths is modified, else false. If no arguments, returns `true` if any path + * in this document is modified. + */ + isModified(path?: string | Array): boolean; + + /** Boolean flag specifying if the document is new. */ + isNew: boolean; + + /** Checks if `path` was selected in the source query which initialized this document. */ + isSelected(path: string): boolean; + + /** Marks the path as having pending changes to write to the db. */ + markModified(path: string, scope?: any): void; + + /** Returns the list of paths that have been modified. */ + modifiedPaths(options?: { includeChildren?: boolean }): Array; + + /** The name of the model */ + modelName: string; + + /** + * Overwrite all values in this document with the values of `obj`, except + * for immutable properties. Behaves similarly to `set()`, except for it + * unsets all properties that aren't in `obj`. + */ + overwrite(obj: AnyObject): this; + + /** + * If this document is a subdocument or populated document, returns the + * document's parent. Returns undefined otherwise. + */ + $parent(): Document | undefined; + + /** Populates document references. */ + populate(path: string | PopulateOptions | (string | PopulateOptions)[]): Promise; + populate(path: string | PopulateOptions | (string | PopulateOptions)[], callback: Callback): void; + populate(path: string, names: string): Promise; + populate(path: string, names: string, callback: Callback): void; + + /** Gets _id(s) used during population of the given `path`. If the path was not populated, returns `undefined`. */ + populated(path: string): any; + + /** Removes this document from the db. */ + remove(options?: QueryOptions): Promise; + remove(options?: QueryOptions, cb?: Callback): void; + + /** Sends a replaceOne command with this document `_id` as the query selector. */ + replaceOne(replacement?: AnyObject, options?: QueryOptions | null, callback?: Callback): Query; + replaceOne(replacement?: AnyObject, options?: QueryOptions | null, callback?: Callback): Query; + + /** Saves this document by inserting a new document into the database if [document.isNew](/docs/api.html#document_Document-isNew) is `true`, or sends an [updateOne](/docs/api.html#document_Document-updateOne) operation with just the modified paths if `isNew` is `false`. */ + save(options?: SaveOptions): Promise; + save(options?: SaveOptions, fn?: Callback): void; + save(fn?: Callback): void; + + /** The document's schema. */ + schema: Schema; + + /** Sets the value of a path, or many paths. */ + set(path: string, val: any, options?: any): this; + set(path: string, val: any, type: any, options?: any): this; + set(value: any): this; + + /** The return value of this method is used in calls to JSON.stringify(doc). */ + toJSON(options: ToObjectOptions & { flattenMaps: false }): LeanDocument; + toJSON(options?: ToObjectOptions): FlattenMaps>; + toJSON>(options?: ToObjectOptions): T; + + /** Converts this document into a plain-old JavaScript object ([POJO](https://masteringjs.io/tutorials/fundamentals/pojo)). */ + toObject(options?: ToObjectOptions): LeanDocument; + toObject(options?: ToObjectOptions): T; + + /** Clears the modified state on the specified path. */ + unmarkModified(path: string): void; + + /** Sends an update command with this document `_id` as the query selector. */ + update(update?: UpdateQuery | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback): Query; + + /** Sends an updateOne command with this document `_id` as the query selector. */ + updateOne(update?: UpdateQuery | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback): Query; + + /** Executes registered validation rules for this document. */ + validate(options: { pathsToSkip?: pathsToSkip }): Promise; + validate(pathsToValidate?: pathsToValidate, options?: any): Promise; + validate(callback: CallbackWithoutResult): void; + validate(pathsToValidate: pathsToValidate, callback: CallbackWithoutResult): void; + validate(pathsToValidate: pathsToValidate, options: any, callback: CallbackWithoutResult): void; + + /** Executes registered validation rules (skipping asynchronous validators) for this document. */ + validateSync(options: { pathsToSkip?: pathsToSkip, [k: string]: any }): Error.ValidationError | null; + validateSync(pathsToValidate?: Array, options?: any): Error.ValidationError | null; + } +} \ No newline at end of file diff --git a/types/index.d.ts b/types/index.d.ts index 8ed68eaf039..1d67e026e1f 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,4 +1,5 @@ /// +/// /// /// @@ -322,247 +323,8 @@ declare module 'mongoose' { getIndexes(): any; } - class Document { - constructor(doc?: any); - - /** This documents _id. */ - _id?: T; - - /** This documents __v. */ - __v?: any; - - /* Get all subdocs (by bfs) */ - $getAllSubdocs(): Document[]; - - /** Don't run validation on this path or persist changes to this path. */ - $ignore(path: string): void; - - /** Checks if a path is set to its default. */ - $isDefault(path: string): boolean; - - /** Getter/setter, determines whether the document was removed or not. */ - $isDeleted(val?: boolean): boolean; - - /** Returns an array of all populated documents associated with the query */ - $getPopulatedDocs(): Document[]; - - /** - * Returns true if the given path is nullish or only contains empty objects. - * Useful for determining whether this subdoc will get stripped out by the - * [minimize option](/docs/guide.html#minimize). - */ - $isEmpty(path: string): boolean; - - /** Checks if a path is invalid */ - $isValid(path: string): boolean; - - /** - * Empty object that you can use for storing properties on the document. This - * is handy for passing data to middleware without conflicting with Mongoose - * internals. - */ - $locals: Record; - - /** Marks a path as valid, removing existing validation errors. */ - $markValid(path: string): void; - - /** - * A string containing the current operation that Mongoose is executing - * on this document. May be `null`, `'save'`, `'validate'`, or `'remove'`. - */ - $op: string | null; - - /** - * Getter/setter around the session associated with this document. Used to - * automatically set `session` if you `save()` a doc that you got from a - * query with an associated session. - */ - $session(session?: mongodb.ClientSession | null): mongodb.ClientSession; - - /** Alias for `set()`, used internally to avoid conflicts */ - $set(path: string, val: any, options?: any): this; - $set(path: string, val: any, type: any, options?: any): this; - $set(value: any): this; - - /** Set this property to add additional query filters when Mongoose saves this document and `isNew` is false. */ - $where: Record; - - /** If this is a discriminator model, `baseModelName` is the name of the base model. */ - baseModelName?: string; - - /** Collection the model uses. */ - collection: Collection; - - /** Connection the model uses. */ - db: Connection; - - /** Removes this document from the db. */ - delete(options?: QueryOptions): QueryWithHelpers; - delete(options: QueryOptions, cb?: Callback): void; - delete(cb: Callback): void; - - /** Removes this document from the db. */ - deleteOne(options?: QueryOptions): QueryWithHelpers; - deleteOne(options: QueryOptions, cb?: Callback): void; - deleteOne(cb: Callback): void; - - /** - * Takes a populated field and returns it to its unpopulated state. If called with - * no arguments, then all populated fields are returned to their unpopulated state. - */ - depopulate(path?: string | string[]): this; - - /** - * Returns the list of paths that have been directly modified. A direct - * modified path is a path that you explicitly set, whether via `doc.foo = 'bar'`, - * `Object.assign(doc, { foo: 'bar' })`, or `doc.set('foo', 'bar')`. - */ - directModifiedPaths(): Array; - - /** - * Returns true if this document is equal to another document. - * - * Documents are considered equal when they have matching `_id`s, unless neither - * document has an `_id`, in which case this function falls back to using - * `deepEqual()`. - */ - equals(doc: Document): boolean; - - /** Hash containing current validation errors. */ - errors?: Error.ValidationError; - - /** Returns the value of a path. */ - get(path: string, type?: any, options?: any): any; - - /** - * Returns the changes that happened to the document - * in the format that will be sent to MongoDB. - */ - getChanges(): UpdateQuery; - - /** The string version of this documents _id. */ - id?: any; - - /** Signal that we desire an increment of this documents version. */ - increment(): this; - - /** - * Initializes the document without setters or marking anything modified. - * Called internally after a document is returned from mongodb. Normally, - * you do **not** need to call this function on your own. - */ - init(obj: any, opts?: any, cb?: Callback): this; - - /** Marks a path as invalid, causing validation to fail. */ - invalidate(path: string, errorMsg: string | NativeError, value?: any, kind?: string): NativeError | null; - - /** Returns true if `path` was directly set and modified, else false. */ - isDirectModified(path: string): boolean; - - /** Checks if `path` was explicitly selected. If no projection, always returns true. */ - isDirectSelected(path: string): boolean; - - /** Checks if `path` is in the `init` state, that is, it was set by `Document#init()` and not modified since. */ - isInit(path: string): boolean; - - /** - * Returns true if any of the given paths is modified, else false. If no arguments, returns `true` if any path - * in this document is modified. - */ - isModified(path?: string | Array): boolean; - - /** Boolean flag specifying if the document is new. */ - isNew: boolean; - - /** Checks if `path` was selected in the source query which initialized this document. */ - isSelected(path: string): boolean; - - /** Marks the path as having pending changes to write to the db. */ - markModified(path: string, scope?: any): void; - - /** Returns the list of paths that have been modified. */ - modifiedPaths(options?: { includeChildren?: boolean }): Array; - - /** The name of the model */ - modelName: string; - - /** - * Overwrite all values in this document with the values of `obj`, except - * for immutable properties. Behaves similarly to `set()`, except for it - * unsets all properties that aren't in `obj`. - */ - overwrite(obj: AnyObject): this; - - /** - * If this document is a subdocument or populated document, returns the - * document's parent. Returns undefined otherwise. - */ - $parent(): Document | undefined; - - /** Populates document references. */ - populate(path: string | PopulateOptions | (string | PopulateOptions)[]): Promise; - populate(path: string | PopulateOptions | (string | PopulateOptions)[], callback: Callback): void; - populate(path: string, names: string): Promise; - populate(path: string, names: string, callback: Callback): void; - - /** Gets _id(s) used during population of the given `path`. If the path was not populated, returns `undefined`. */ - populated(path: string): any; - - /** Removes this document from the db. */ - remove(options?: QueryOptions): Promise; - remove(options?: QueryOptions, cb?: Callback): void; - - /** Sends a replaceOne command with this document `_id` as the query selector. */ - replaceOne(replacement?: AnyObject, options?: QueryOptions | null, callback?: Callback): Query; - replaceOne(replacement?: AnyObject, options?: QueryOptions | null, callback?: Callback): Query; - - /** Saves this document by inserting a new document into the database if [document.isNew](/docs/api.html#document_Document-isNew) is `true`, or sends an [updateOne](/docs/api.html#document_Document-updateOne) operation with just the modified paths if `isNew` is `false`. */ - save(options?: SaveOptions): Promise; - save(options?: SaveOptions, fn?: Callback): void; - save(fn?: Callback): void; - - /** The document's schema. */ - schema: Schema; - - /** Sets the value of a path, or many paths. */ - set(path: string, val: any, options?: any): this; - set(path: string, val: any, type: any, options?: any): this; - set(value: any): this; - - /** The return value of this method is used in calls to JSON.stringify(doc). */ - toJSON(options: ToObjectOptions & { flattenMaps: false }): LeanDocument; - toJSON(options?: ToObjectOptions): FlattenMaps>; - toJSON>(options?: ToObjectOptions): T; - - /** Converts this document into a plain-old JavaScript object ([POJO](https://masteringjs.io/tutorials/fundamentals/pojo)). */ - toObject(options?: ToObjectOptions): LeanDocument; - toObject(options?: ToObjectOptions): T; - - /** Clears the modified state on the specified path. */ - unmarkModified(path: string): void; - - /** Sends an update command with this document `_id` as the query selector. */ - update(update?: UpdateQuery | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback): Query; - - /** Sends an updateOne command with this document `_id` as the query selector. */ - updateOne(update?: UpdateQuery | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback): Query; - - /** Executes registered validation rules for this document. */ - validate(options:{ pathsToSkip?: pathsToSkip }): Promise; - validate(pathsToValidate?: pathsToValidate, options?: any): Promise; - validate(callback: CallbackWithoutResult): void; - validate(pathsToValidate: pathsToValidate, callback: CallbackWithoutResult): void; - validate(pathsToValidate: pathsToValidate, options: any, callback: CallbackWithoutResult): void; - - /** Executes registered validation rules (skipping asynchronous validators) for this document. */ - validateSync(options:{pathsToSkip?: pathsToSkip, [k:string]: any }): Error.ValidationError | null; - validateSync(pathsToValidate?: Array, options?: any): Error.ValidationError | null; - } - /** A list of paths to validate. If set, Mongoose will validate only the modified paths that are in the given list. */ type pathsToValidate = string[] | string; - /** A list of paths to skip. If set, Mongoose will validate every modified path that is not in this list. */ - type pathsToSkip = string[] | string; interface AcceptsDiscriminator { /** Adds a discriminator type. */ From 6eb20e6c52bdb39c6bc016b0da86a56cb9524b29 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Sun, 6 Mar 2022 03:37:53 +0100 Subject: [PATCH 2/2] improve document typings --- test/types/document.test.ts | 28 ++++++++++++++++++---- types/document.d.ts | 46 ++++++++++++++++++------------------- 2 files changed, 46 insertions(+), 28 deletions(-) diff --git a/test/types/document.test.ts b/test/types/document.test.ts index a287d6d7512..3719976acd4 100644 --- a/test/types/document.test.ts +++ b/test/types/document.test.ts @@ -1,5 +1,5 @@ import { Schema, model, Model, Document, Error, Types } from 'mongoose'; -import { expectError } from 'tsd'; +import { expectError, expectType } from 'tsd'; const schema: Schema = new Schema({ name: { type: 'String', required: true }, address: new Schema({ city: { type: String, required: true } }) }); @@ -14,8 +14,15 @@ const Test = model('Test', schema); void async function main() { const doc: ITest = await Test.findOne().orFail(); - const p: Promise = doc.remove(); - await p; + expectType>(doc.remove()); + expectType(doc.remove({}, (err, doc) => { + expectType(err); + expectType(doc); + })); + expectType(doc.remove((err, doc) => { + expectType(err); + expectType(doc); + })); }(); @@ -33,6 +40,17 @@ void async function run() { test.validate({ pathsToSkip: 'name age' }); test.validateSync({ pathsToSkip: ['name', 'age'] }); test.validateSync({ pathsToSkip: 'name age' }); + test.validateSync({ pathsToSkip: 'name age', blub: 1 }); + expectType>(test.save()); + expectType>(test.save({})); + expectType(test.save({}, (err, doc) => { + expectType(err); + expectType(doc); + })); + expectType(test.save((err, doc) => { + expectType(err); + expectType(doc); + })); })(); function gh10526(arg1: Model) { @@ -58,7 +76,7 @@ function testMethods(): void { const UserModel = model('User', schema); const doc = new UserModel({ first: 'test', last: 'test' }); - doc.fullName().toUpperCase(); + expectType(doc.fullName()); } function testRequiredId(): void { @@ -114,7 +132,7 @@ async function gh11117(): Promise { } ]); const json = items[0].toJSON(); - const someDate: Date = json.someDate; + expectType(json.someDate); } function gh11085(): void { diff --git a/types/document.d.ts b/types/document.d.ts index b6530f548b0..efd9b76dc91 100644 --- a/types/document.d.ts +++ b/types/document.d.ts @@ -51,20 +51,20 @@ declare module 'mongoose' { /** * A string containing the current operation that Mongoose is executing - * on this document. May be `null`, `'save'`, `'validate'`, or `'remove'`. + * on this document. Can be `null`, `'save'`, `'validate'`, or `'remove'`. */ - $op: string | null; + $op: 'save' | 'validate' | 'remove' | null; /** * Getter/setter around the session associated with this document. Used to * automatically set `session` if you `save()` a doc that you got from a * query with an associated session. */ - $session(session?: mongodb.ClientSession | null): mongodb.ClientSession; + $session(session?: mongodb.ClientSession | null): mongodb.ClientSession | null; /** Alias for `set()`, used internally to avoid conflicts */ - $set(path: string, val: any, options?: any): this; $set(path: string, val: any, type: any, options?: any): this; + $set(path: string, val: any, options?: any): this; $set(value: any): this; /** Set this property to add additional query filters when Mongoose saves this document and `isNew` is false. */ @@ -80,14 +80,14 @@ declare module 'mongoose' { db: Connection; /** Removes this document from the db. */ + delete(options: QueryOptions, callback: Callback): void; + delete(callback: Callback): void; delete(options?: QueryOptions): QueryWithHelpers; - delete(options: QueryOptions, cb?: Callback): void; - delete(cb: Callback): void; /** Removes this document from the db. */ + deleteOne(options: QueryOptions, callback: Callback): void; + deleteOne(callback: Callback): void; deleteOne(options?: QueryOptions): QueryWithHelpers; - deleteOne(options: QueryOptions, cb?: Callback): void; - deleteOne(cb: Callback): void; /** * Takes a populated field and returns it to its unpopulated state. If called with @@ -111,7 +111,7 @@ declare module 'mongoose' { */ equals(doc: Document): boolean; - /** Hash containing current validation errors. */ + /** Returns the current validation errors. */ errors?: Error.ValidationError; /** Returns the value of a path. */ @@ -134,7 +134,7 @@ declare module 'mongoose' { * Called internally after a document is returned from mongodb. Normally, * you do **not** need to call this function on your own. */ - init(obj: any, opts?: any, cb?: Callback): this; + init(obj: AnyObject, opts?: AnyObject, callback?: Callback): this; /** Marks a path as invalid, causing validation to fail. */ invalidate(path: string, errorMsg: string | NativeError, value?: any, kind?: string): NativeError | null; @@ -149,7 +149,7 @@ declare module 'mongoose' { isInit(path: string): boolean; /** - * Returns true if any of the given paths is modified, else false. If no arguments, returns `true` if any path + * Returns true if any of the given paths are modified, else false. If no arguments, returns `true` if any path * in this document is modified. */ isModified(path?: string | Array): boolean; @@ -183,33 +183,33 @@ declare module 'mongoose' { $parent(): Document | undefined; /** Populates document references. */ - populate(path: string | PopulateOptions | (string | PopulateOptions)[]): Promise; populate(path: string | PopulateOptions | (string | PopulateOptions)[], callback: Callback): void; - populate(path: string, names: string): Promise; populate(path: string, names: string, callback: Callback): void; + populate(path: string, names: string): Promise; + populate(path: string | PopulateOptions | (string | PopulateOptions)[]): Promise; /** Gets _id(s) used during population of the given `path`. If the path was not populated, returns `undefined`. */ populated(path: string): any; /** Removes this document from the db. */ + remove(options: QueryOptions, callback: Callback): void; + remove(callback: Callback): void; remove(options?: QueryOptions): Promise; - remove(options?: QueryOptions, cb?: Callback): void; /** Sends a replaceOne command with this document `_id` as the query selector. */ replaceOne(replacement?: AnyObject, options?: QueryOptions | null, callback?: Callback): Query; - replaceOne(replacement?: AnyObject, options?: QueryOptions | null, callback?: Callback): Query; /** Saves this document by inserting a new document into the database if [document.isNew](/docs/api.html#document_Document-isNew) is `true`, or sends an [updateOne](/docs/api.html#document_Document-updateOne) operation with just the modified paths if `isNew` is `false`. */ + save(options: SaveOptions, callback: Callback): void; + save(callback: Callback): void; save(options?: SaveOptions): Promise; - save(options?: SaveOptions, fn?: Callback): void; - save(fn?: Callback): void; /** The document's schema. */ schema: Schema; /** Sets the value of a path, or many paths. */ - set(path: string, val: any, options?: any): this; set(path: string, val: any, type: any, options?: any): this; + set(path: string, val: any, options?: any): this; set(value: any): this; /** The return value of this method is used in calls to JSON.stringify(doc). */ @@ -231,14 +231,14 @@ declare module 'mongoose' { updateOne(update?: UpdateQuery | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: Callback): Query; /** Executes registered validation rules for this document. */ - validate(options: { pathsToSkip?: pathsToSkip }): Promise; - validate(pathsToValidate?: pathsToValidate, options?: any): Promise; - validate(callback: CallbackWithoutResult): void; + validate(pathsToValidate: pathsToValidate, options: AnyObject, callback: CallbackWithoutResult): void; validate(pathsToValidate: pathsToValidate, callback: CallbackWithoutResult): void; - validate(pathsToValidate: pathsToValidate, options: any, callback: CallbackWithoutResult): void; + validate(callback: CallbackWithoutResult): void; + validate(pathsToValidate?: pathsToValidate, options?: AnyObject): Promise; + validate(options: { pathsToSkip?: pathsToSkip }): Promise; /** Executes registered validation rules (skipping asynchronous validators) for this document. */ validateSync(options: { pathsToSkip?: pathsToSkip, [k: string]: any }): Error.ValidationError | null; - validateSync(pathsToValidate?: Array, options?: any): Error.ValidationError | null; + validateSync(pathsToValidate?: Array, options?: AnyObject): Error.ValidationError | null; } } \ No newline at end of file