From cddd4f8a2fd0a29cdd2401f24f66a469e1db5ef8 Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 9 Oct 2016 20:43:46 -0400 Subject: [PATCH] fixes return types for mongoose document array create() and id() --- mongoose/mongoose-tests.ts | 10 ++++++++++ mongoose/mongoose.d.ts | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/mongoose/mongoose-tests.ts b/mongoose/mongoose-tests.ts index 7c5e9adcfc..8c0771e6d2 100644 --- a/mongoose/mongoose-tests.ts +++ b/mongoose/mongoose-tests.ts @@ -492,6 +492,16 @@ documentArray.toObject({}).length; documentArray.$shift(); /* inherited from Native Array */ documentArray.concat(); +/* practical example */ +interface MySubEntity1 extends mongoose.Types.Subdocument { + property1: string; + property2: string; +} +interface MyEntity1 extends mongoose.Document { + sub: mongoose.Types.DocumentArray +} +var newEnt: MyEntity1; +var newSub: MySubEntity1 = newEnt.sub.create({ property1: "example", property2: "example" }); /* * section types/buffer.js diff --git a/mongoose/mongoose.d.ts b/mongoose/mongoose.d.ts index 928949ec59..5c1f0a4edb 100644 --- a/mongoose/mongoose.d.ts +++ b/mongoose/mongoose.d.ts @@ -1045,13 +1045,13 @@ declare module "mongoose" { * This is the same subdocument constructor used for casting. * @param obj the value to cast to this arrays SubDocument schema */ - create(obj: Object): Subdocument; + create(obj: Object): T; /** * Searches array items for the first document with a matching _id. * @returns the subdocument or null if not found. */ - id(id: ObjectId | string | number | NativeBuffer): Embedded; + id(id: ObjectId | string | number | NativeBuffer): T; /** Helper for console.log */ inspect(): T[];