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[];