From b5a573efa06322ed1542f679defca90db2590468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fa=CC=81bio=20Batista?= Date: Fri, 7 Apr 2017 19:43:25 -0300 Subject: [PATCH] @types/mongoose: better docs --- types/mongoose/README.md | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/types/mongoose/README.md b/types/mongoose/README.md index 8684f7f2b6..822e66d1f6 100644 --- a/types/mongoose/README.md +++ b/types/mongoose/README.md @@ -190,25 +190,15 @@ Full example for [Passport Local Mongoose](https://github.com/DefinitelyTyped/De #### FAQ and Common Mistakes **Q: When to use `mongoose.Schema.Types.ObjectId` and `mongoose.Types.ObjectId`**
-When creating schemas in code use `mongoose.Schema.Types.ObjectId`: +When creating schemas in code use `mongoose.Schema.Types.ObjectId`. This is not a type, this is an instance +of `SchemaType` containing metadata for the ObjectId type: ```typescript var UserSchema = new mongoose.Schema({ id: mongoose.Schema.Types.ObjectId }); ``` -Mongoose uses `mongoose.Schema.Types.ObjectId` internally to create the schema. -However, if you define your interface like this: +When defining your interface, you should use the type definition `mongoose.Types.ObjectId`: ```typescript -interface IUser extends mongoose.Document { - id: mongoose.Schema.Types.ObjectId; -} -... -user.id = new mongoose.Types.ObjectId(); -``` -To use it, you will need to `/// ` in one of your source code files, - - -To assign the new promise library in your code, you will need to use one of the following options (since interface IUser extends mongoose.Document { id: mongoose.Types.ObjectId; // for type-checking, doesn't affect code behaviour }