mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-23 04:49:15 +08:00
added missing ObjectId methods, changed Document _id property from string to ObjectId
This commit is contained in:
@@ -364,5 +364,14 @@ schema.virtual('display_name')
|
||||
.get(function(): string { return this.name; })
|
||||
.set((value: string): void => {});
|
||||
|
||||
var id : mongoose.Types.ObjectId;
|
||||
var id: mongoose.Types.ObjectId = new mongoose.Types.ObjectId('foo');
|
||||
var id2: mongoose.Types.ObjectId = new mongoose.Types.ObjectId(123);
|
||||
var id2: mongoose.Types.ObjectId = mongoose.Types.ObjectId.createFromTime(123);
|
||||
var id2: mongoose.Types.ObjectId = mongoose.Types.ObjectId.createFromHexString('foo');
|
||||
var s = id.toHexString();
|
||||
var valid = id.isValid();
|
||||
var eq = id.equals(id2);
|
||||
|
||||
var kitty1 = new Kitty({});
|
||||
var kitty2 = new Kitty({});
|
||||
var kittyEq = kitty1._id.equals(kitty2._id);
|
||||
10
mongoose/mongoose.d.ts
vendored
10
mongoose/mongoose.d.ts
vendored
@@ -79,7 +79,13 @@ declare module "mongoose" {
|
||||
}
|
||||
export module Types {
|
||||
export class ObjectId {
|
||||
toHexString(): string;
|
||||
constructor(id: string|number);
|
||||
toHexString(): string;
|
||||
equals(other: ObjectId): boolean;
|
||||
getTimestamp(): Date;
|
||||
isValid(): boolean;
|
||||
static createFromTime(time: number): ObjectId;
|
||||
static createFromHexString(hexString: string): ObjectId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,7 +380,7 @@ declare module "mongoose" {
|
||||
|
||||
export interface Document {
|
||||
id?: string;
|
||||
_id: string;
|
||||
_id: Types.ObjectId;
|
||||
|
||||
equals(doc: Document): boolean;
|
||||
get(path: string, type?: new(...args: any[]) => any): any;
|
||||
|
||||
Reference in New Issue
Block a user