From ff1e9ee2539e54035e80739b0eb9605cb6222703 Mon Sep 17 00:00:00 2001 From: Wose Date: Thu, 22 Nov 2018 09:46:16 -0500 Subject: [PATCH 1/3] Switch Mongoose post hook overload order Fixes incorrect selection of function overload --- types/mongoose/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/mongoose/index.d.ts b/types/mongoose/index.d.ts index 5963be87ed..aa24ca16b1 100644 --- a/types/mongoose/index.d.ts +++ b/types/mongoose/index.d.ts @@ -811,11 +811,11 @@ declare module "mongoose" { * @param fn callback */ post(method: string, fn: ( - error: mongodb.MongoError, doc: T, next: (err?: NativeError) => void - ) => void): this; + doc: T, next: (err?: NativeError) => void + ) => void): this; post(method: string, fn: ( - doc: T, next: (err?: NativeError) => void + error: mongodb.MongoError, doc: T, next: (err?: NativeError) => void ) => void): this; /** From 7191616daf83a72a4636724ffe998b4c21f82579 Mon Sep 17 00:00:00 2001 From: Wose Date: Thu, 22 Nov 2018 10:16:38 -0500 Subject: [PATCH 2/3] Update types in mongoose-tests.ts for post hook arguments --- types/mongoose/mongoose-tests.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/mongoose/mongoose-tests.ts b/types/mongoose/mongoose-tests.ts index c8873f85b3..f713ba8538 100644 --- a/types/mongoose/mongoose-tests.ts +++ b/types/mongoose/mongoose-tests.ts @@ -491,12 +491,12 @@ preHookTestSchemaArr.push( ); schema -.post('save', function (error, doc, next) { +.post('save', function (error: mongoose.Error, doc: mongoose.Document, next: (err?: mongoose.NativeError) => void) { error.stack; doc.model; next.apply; }) -.post('save', function (doc: mongoose.Document, next: Function) { +.post('save', function (doc: mongoose.Document, next: (err?: mongoose.NativeError) => void) { doc.model; next(new Error()); }) From 402324af7b7157e809f604d4536e7fd9cda24ca2 Mon Sep 17 00:00:00 2001 From: Wose Date: Thu, 22 Nov 2018 11:35:25 -0500 Subject: [PATCH 3/3] Fix extra spaces in previous commit (mongoose-posthook-overload) --- types/mongoose/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/mongoose/index.d.ts b/types/mongoose/index.d.ts index aa24ca16b1..3672b75b8f 100644 --- a/types/mongoose/index.d.ts +++ b/types/mongoose/index.d.ts @@ -811,8 +811,8 @@ declare module "mongoose" { * @param fn callback */ post(method: string, fn: ( - doc: T, next: (err?: NativeError) => void - ) => void): this; + doc: T, next: (err?: NativeError) => void + ) => void): this; post(method: string, fn: ( error: mongodb.MongoError, doc: T, next: (err?: NativeError) => void