From c0d65d4b72432f755cfd5a08426abe3b59ffc30a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Snorre=20Magnus=20Dav=C3=B8en?= Date: Mon, 9 Jan 2017 10:56:16 +0100 Subject: [PATCH] mongoose: Change MongooseDocument.set return type Fix: Change MongooseDocument.set() return type from void to this. See http://mongoosejs.com/docs/api.html#document_Document-set Modify doc.set() examples in test file to chain the set method in order to test the "this" return type. --- mongoose/index.d.ts | 6 +++--- mongoose/mongoose-tests.ts | 7 ++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/mongoose/index.d.ts b/mongoose/index.d.ts index 92655b871d..56ad48e617 100644 --- a/mongoose/index.d.ts +++ b/mongoose/index.d.ts @@ -1010,9 +1010,9 @@ declare module "mongoose" { * @param type optionally specify a type for "on-the-fly" attributes * @param options optionally specify options that modify the behavior of the set */ - set(path: string, val: any, options?: Object): void; - set(path: string, val: any, type: any, options?: Object): void; - set(value: Object): void; + set(path: string, val: any, options?: Object): this; + set(path: string, val: any, type: any, options?: Object): this; + set(value: Object): this; /** * The return value of this method is used in calls to JSON.stringify(doc). diff --git a/mongoose/mongoose-tests.ts b/mongoose/mongoose-tests.ts index be63241296..c6dfe20fdc 100644 --- a/mongoose/mongoose-tests.ts +++ b/mongoose/mongoose-tests.ts @@ -449,10 +449,7 @@ doc.populate(function (err, doc) { }); }); doc.populated('path'); -doc.set('path', 999, {}); -doc.set({ - path: 999 -}); +doc.set('path', 999, {}).set({ path: 999 }); doc.toJSON({ getters: true, virtuals: false @@ -1494,4 +1491,4 @@ const extended: mongoose.Model = base.discriminator('extende const x = new extended({ username: 'hi', // required in baseSchema email: 'beddiw', // required in extededSchema -}); \ No newline at end of file +});