question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript instanceof mongoose.Error

See original GitHub issue

Do you want to request a feature or report a bug?

bug

What is the current behavior?

Following the example in https://mongoosejs.com/docs/api/error.html#error_Error

const Model = mongoose.model('Test', new mongoose.Schema({ answer: Number }))
const doc = new Model({ answer: 'not a number' })
const err = doc.validateSync()

err instanceof mongoose.Error // true

I got the error in err instanceof mongoose.Error

namespace Error
The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type.ts(2359)

If the current behavior is a bug, please provide the steps to reproduce.

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that “latest” is not a version.

node 16.14.2 mongoose 6.3.4

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
Uzlopakcommented, May 28, 2022

It is a documentation error. You have to check against mongoose.Error.ValidationError

0reactions
amorimfilipecommented, May 29, 2022

@Uzlopak Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error from mongoose is not an instance of MongoError?
Using the Debugging tool, I can see the constructor of e is class MongoError extends Error , however the result of e instanceof...
Read more >
Error Handling Middlewares and TypeScript #9745 - GitHub
I'd argue this type definition is correct because the error parameter to error handling middleware isn't necessarily a MongoError instance.
Read more >
Mongoose v6.8.1: Error
An instance of this error class will be returned when you call save() multiple times on the same document in parallel. See the...
Read more >
Working with Mongoose in TypeScript - The Code Barbarian
User is technically not a class according to @types/mongoose , because TypeScript doesn't have good support for functions that return classes.
Read more >
Best Practices for Node.js Error-handling - Toptal
Jay is a full-stack developer with extensive experience in computer science. He specializes in JavaScript but is also proficient in Django, RoR, GraphQL,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found