diff --git a/mongoose/index.d.ts b/mongoose/index.d.ts index 5546a177d7..e7446fccc3 100644 --- a/mongoose/index.d.ts +++ b/mongoose/index.d.ts @@ -609,9 +609,13 @@ declare module "mongoose" { * @param method name of the method to hook * @param fn callback */ - post(method: string, fn: (doc: T, next: (err?: NativeError) => void, - ...otherArgs: any[]) => void): this; - post(method: string, fn: (doc: T) => void, ...args: any[]): this; + post(method: string, fn: ( + error: mongodb.MongoError, doc: T, next: (err?: NativeError) => void + ) => void): this; + + post(method: string, fn: ( + doc: T, next: (err?: NativeError) => void + ) => void): this; /** * Defines a pre hook for the document. diff --git a/mongoose/mongoose-tests.ts b/mongoose/mongoose-tests.ts index df93a10476..28785d301e 100644 --- a/mongoose/mongoose-tests.ts +++ b/mongoose/mongoose-tests.ts @@ -266,8 +266,19 @@ schema.plugin(function (schema, opts) { schema.get('path'); opts.hasOwnProperty(''); }).plugin(cb, {opts: true}); -schema.post('post', function (doc) {}).post('post', function (doc, next) { +import { Schema, Model, Document, NativeError } from 'mongoose'; +schema +.post('save', function (error, doc, next) { + error.stack; + doc.model; + next.apply; +}) +.post('save', function (doc: mongoose.Document, next: Function) { + doc.model; next(new Error()); +}) +.post('save', function (doc: mongoose.Document) { + doc.model; }); schema.queue('m1', [1, 2, 3]).queue('m2', [[]]); schema.remove('path');