Closed
Description
Do you want to request a feature or report a bug?
Bug.
What is the current behavior?
Current type:
(property) Error.ValidationError.errors: {
[path: string]: mongoose.Error.ValidatorError | mongoose.Error.CastError;
}
If the current behavior is a bug, please provide the steps to reproduce.
const mongoose = require('mongoose');
const userSchema = new mongoose.Schema({
name: { type: String, required: true },
address: new mongoose.Schema({ city: { type: String, required: true } }),
});
const User = mongoose.model('User', userSchema);
const user = new User({ name: {}, address: {} });
const error = user.validateSync();
// The errors property contains instances of CastError, ValidatorError and ValidationError
if (error instanceof mongoose.Error.ValidationError) {
console.log(error.errors.name instanceof mongoose.Error.CastError); // true
console.log(error.errors['address.city'] instanceof mongoose.Error.ValidatorError); // true
console.log(error.errors.address instanceof mongoose.Error.ValidationError); // true
}
What is the expected behavior?
Expected type:
(property) Error.ValidationError.errors: {
[path: string]: mongoose.Error.ValidatorError | mongoose.Error.CastError | mongoose.Error.ValidationError;
}
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node.js: 14.17.0
Mongoose: 5.12.12
MongoDB: 4.4.6