Skip to content

Commit 8120c8f

Browse files
committed
fix(index.d.ts): rename EnforceDocument -> HydratedDocument, export HydratedDocument for easier typing for users
Fix #10843
1 parent 577b604 commit 8120c8f

File tree

2 files changed

+85
-70
lines changed

2 files changed

+85
-70
lines changed

docs/typescript.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ async function run(): Promise<void> {
5353
You as the developer are responsible for ensuring that your document interface lines up with your Mongoose schema.
5454
For example, Mongoose won't report an error if `email` is `required` in your Mongoose schema but optional in your document interface.
5555

56+
The `UserModel()` constructor returns an instance of `HydratedDocument<User>`.
57+
`User` is a _document interface_, it represents the raw object structure that `User` objects look like in MongoDB.
58+
`HydratedDocument<User>` represents a hydrated Mongoose document, with methods, virtuals, and other Mongoose-specific features.
59+
60+
```ts
61+
import { HydratedDocument } from 'mongoose';
62+
63+
const doc: HydratedDocument<User> = new UserModel({
64+
name: 'Bill',
65+
66+
avatar: 'https://i.imgur.com/dM7Thhn.png'
67+
});
68+
```
69+
5670
### Using `extends Document`
5771

5872
Alternatively, your document interface can extend Mongoose's `Document` class.

0 commit comments

Comments
 (0)