Closed copilotwwai closed 1 month ago
Including timestamp: true
doesn't change your TS schema - you need to declare these properties yourself, otherwise you'll get complication errors.
Thank you for taking the time to submit your report! From the looks of it, this could be better discussed on our Discord. If you haven't already, please join here and send a new post in the # 🐈 nestjs-help forum. Make sure to include a link to this issue, so you don't need to write it all again. We have a large community of helpful members, who will assist you in getting this to work.
Is there an existing issue for this?
Current behavior
I'm experiencing an issue where the createdAt and updatedAt fields are not accessible on a HydratedDocument type in my NestJS + Mongoose application, even after updating to the latest versions of @nestjs/mongoose and mongoose. The fields createdAt and updatedAt are still not recognized by TypeScript on the document type, despite the fact that the schema is defined with timestamps: true. Here is the error I get when trying to access createdAt:
Minimum reproduction code
https://github.com/nestjs/mongoose
Steps to reproduce
1- I updated to the latest versions of @nestjs/mongoose and mongoose using:
2- Confirmed that timestamps: true is enabled in the schema. 3- Restarted the TypeScript server and cleared cache to ensure no cached types were used.
When I try to access createdAt or updatedAt:
Expected behavior
I believe this should work automatically as per the changes introduced in PR #2236, where the createdAt and updatedAt properties should be inferred based on the timestamps: true option in the schema. However, these fields are still missing from the document type in my TypeScript code.
Additional Information: No manual extension or declaration of createdAt and updatedAt should be required according to the latest update. I would appreciate any clarification on whether this issue persists and what the recommended workaround would be in the meantime.
Package version
10.0.10
mongoose version
8.7.0
NestJS version
10.2.6
Node.js version
18.18.0
In which operating systems have you tested?
Other
No response