-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Closed
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
6.4.2
Node.js version
18
MongoDB server version
5.0
Description
I've found a few more bugs in auto infer type
- Adding an object directly to the array doesn't infer type correctly
const userSchema = new Schema({
users: [
{
username: { type: String }
}
]
});
- passing function in default makes the key optional
const userSchema = new Schema({
createdAt: { type: Date, default: Date.now }
});
- Array type becomes
Array
instead ofTypes.DocumentArray
which makes pushing fields difficult
const userSchema = new Schema({
users: [
new Schema({
username: { type: String },
credit: { type: Number, default: 0 }
})
]
});
const userModel = model('user', userSchema);
const data = await userModel.findOne();
data!.users.push({ username: 'parbez' });
// ts warns to add createdAt which can be solved using Types.DocumentArray
- Adding empty object as default doesn't makes the key required
const userSchema = new Schema({
data: { type: { role: Object }, default: {} }
});
- Assigning an object directly to a key doesn't infer type correctly
const userSchema = new Schema({
data: {
username: String
}
});
Steps to Reproduce
added code blocks above
Expected Behavior
No response
Metadata
Metadata
Assignees
Labels
No labels