From 97ec10cb6c917dce7668f3833679506162c0f5c4 Mon Sep 17 00:00:00 2001 From: John Hasselkus Date: Tue, 12 Jan 2016 10:14:33 -0600 Subject: [PATCH] mongoose.d.ts Document interface should define _id as any In the Document interface definition of mongoose.d.ts, the _id field definition of _id: Types.ObjectId was wrong, as it can be any type. This commit changes the definition to _id: any to allow interfaces that extend Document to refine the definition of _id as appropriate to match the schema of the model/collection. --- mongoose/mongoose-tests.ts | 10 ++++++++++ mongoose/mongoose.d.ts | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/mongoose/mongoose-tests.ts b/mongoose/mongoose-tests.ts index 3cb9c3575..806272f45 100644 --- a/mongoose/mongoose-tests.ts +++ b/mongoose/mongoose-tests.ts @@ -41,6 +41,16 @@ var schema: mongoose.Schema = new Schema({ name: String }, { collection: 'actor' schema.set('collection', 'actor'); var Model = mongoose.model('Actor', schema, 'actor'); +interface IZip extends mongoose.Document { + _id: string; +} +interface IPerson extends mongoose.Document { + _id: mongoose.Types.ObjectId; +} +interface IThing extends mongoose.Document { + _id: number; +} + var names: string[] = mongoose.modelNames(); var names: string[] = db.modelNames(); mongoose.plugin((schema: mongoose.Schema) => { diff --git a/mongoose/mongoose.d.ts b/mongoose/mongoose.d.ts index b97162267..6871dc344 100644 --- a/mongoose/mongoose.d.ts +++ b/mongoose/mongoose.d.ts @@ -423,7 +423,7 @@ declare module "mongoose" { export interface Document { id?: string; - _id: Types.ObjectId; + _id: any; equals(doc: Document): boolean; get(path: string, type?: new(...args: any[]) => any): any;