-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Closed
Labels
typescriptTypes or Types-test related issue / Pull RequestTypes or Types-test related issue / Pull Request
Milestone
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Mongoose version
8.0.4
Node.js version
16
MongoDB server version
6.0.6
Typescript version (if applicable)
5.2.2
Description
Hello,
I think the SchemaType
of a schema should have an _id
field by default
For e.g, we have createdAt
, and updatedAt
field in the type when we set the option { timestamps: true }
.
Which is not the case when we set options: { _id: true }
Steps to Reproduce
import mongoose, { type InferSchemaType, Schema } from "mongoose";
const eventSchema = new mongoose.Schema({ url: String }, { timestamps: true });
const Event = mongoose.model("Event", eventSchema);
type EventDoc = InferSchemaType<typeof eventSchema>;
async function run() {
const event = {} as EventDoc;
// createdAt exists because timestamps: true, which is totally OK
event.createdAt = new Date();
// WRONG: _id does not exist on type EventDoc, this should be set, since options._id is to true by default
event._id; // ERROR
}
run();
Expected Behavior
No response
Metadata
Metadata
Assignees
Labels
typescriptTypes or Types-test related issue / Pull RequestTypes or Types-test related issue / Pull Request