mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-16 02:57:24 +08:00
fixes return types for mongoose document array create() and id()
This commit is contained in:
@@ -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
|
||||
|
||||
4
mongoose/mongoose.d.ts
vendored
4
mongoose/mongoose.d.ts
vendored
@@ -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[];
|
||||
|
||||
Reference in New Issue
Block a user