Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing of ValidationError's errors property is incomplete #10320

Closed
thiagokisaki opened this issue Jun 3, 2021 · 0 comments · Fixed by #10326
Closed

Typing of ValidationError's errors property is incomplete #10320

thiagokisaki opened this issue Jun 3, 2021 · 0 comments · Fixed by #10326
Assignees
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@thiagokisaki
Copy link
Contributor

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

@IslandRhythms IslandRhythms added the confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. label Jun 3, 2021
@vkarpov15 vkarpov15 added this to the 5.12.13 milestone Jun 4, 2021
@IslandRhythms IslandRhythms linked a pull request Jun 4, 2021 that will close this issue
@vkarpov15 vkarpov15 modified the milestones: 5.12.13, 5.12.14 Jun 4, 2021
vkarpov15 added a commit that referenced this issue Jun 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants