You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched existing issues to ensure the bug has not already been reported
Mongoose version
8.5.3
Node.js version
19.8
MongoDB server version
7.0.12
Typescript version (if applicable)
No response
Description
when I use type returned by InferRawDocType it is supposed to be the same as the type returned from function .lean(), but using the document from then() it throws a type error, reproducsible code below
Steps to Reproduce
import mongoose
const schemaDefinition = {
email : {
type : String ,
trim: true,
required : true,
unique: true,
lowercase: true
},
password : {
type : String ,
required : true,
},
dateOfBirth: {
type: Date,
required: true
}
}
const UserModel = mongoose.model('User' , UserSchema);
type UserType = mongoose.InferRawDocType< typeof schemaDefinition>;
let user: UserType | null;
async function queryById(id: string ){
let user: UserType | null ;
UserModel.findById(id).lean().then( result=>{
if (result){
user = result
}
})
}
this code gives type error
Type 'FlattenMaps<{ email: string; password: string; firstName: string; lastName: string; dateOfBirth: Date; }> & { _id: ObjectId; }' is not assignable to type '{ email: string; password: string; firstName: string; lastName: string; dateOfBirth: Date; } | null'.
Type 'FlattenMaps<{ email: string; password: string; firstName: string; lastName: string; dateOfBirth: Date; }> & { _id: ObjectId; }' is not assignable to type '{ email: string; password: string; firstName: string; lastName: string; dateOfBirth: Date; }'.
Types of property 'dateOfBirth' are incompatible.
Type 'Date' is missing the following properties from type 'Date': expires, max, min, defaultOptions, and 21 more.
Also whenever i use user._id it throws error Property '_id' does not exist on type '{ email: string; password: string; firstName: string; lastName: string; dateOfBirth: Date; }
Expected Behavior
No response
The text was updated successfully, but these errors were encountered:
If you need to explicitly get the raw document type (the value returned from doc.toObject(), await Model.findOne().lean(), etc.) from your schema definition, you can use Mongoose's inferRawDocType helper as follows:
Tbh,I am not sure if it's just a bug or I misunderstood it either way thank you for your time
Prerequisites
Mongoose version
8.5.3
Node.js version
19.8
MongoDB server version
7.0.12
Typescript version (if applicable)
No response
Description
when I use type returned by InferRawDocType it is supposed to be the same as the type returned from function .lean(), but using the document from
then()
it throws a type error, reproducsible code belowSteps to Reproduce
this code gives type error
Also whenever i use
user._id
it throws errorProperty '_id' does not exist on type '{ email: string; password: string; firstName: string; lastName: string; dateOfBirth: Date; }
Expected Behavior
No response
The text was updated successfully, but these errors were encountered: