fixes return types for mongoose document array create() and id()

This commit is contained in:
Simon
2016-10-09 20:43:46 -04:00
parent e623c6b316
commit cddd4f8a2f
2 changed files with 12 additions and 2 deletions

View File

@@ -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<MySubEntity>
}
var newEnt: MyEntity1;
var newSub: MySubEntity1 = newEnt.sub.create({ property1: "example", property2: "example" });
/*
* section types/buffer.js

View File

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