Typescript instanceof mongoose.Error
See original GitHub issueDo 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:
- Created a year ago
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It is a documentation error. You have to check against mongoose.Error.ValidationError
@Uzlopak Thank you!