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.

HookNextFunction missing from local types?

See original GitHub issue

We were recently attempting to update to mongoose 5.11.3 and ran into this compilation error:

src/model/document/ModelRef.ts:4:25 - error TS2305: Module '"mongoose"' has no exported member 'HookNextFunction'.

4 import { Schema, Model, HookNextFunction } from 'mongoose'
                          ~~~~~~~~~~~~~~~~

This is currently defined in the @types/mongoose but is not defined in the mongoose types. Is this intended behavior (so we need to now import these from another module) or unintentional? If it’s unintentional, I think some of the other Hook*** are missing as well.

Thanks.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
sean-daleycommented, Dec 4, 2020

No worries, we can add this type back if it causes a lot of trouble for you. Are there any other types you’re missing?

We are hitting a few other issues but it’s in some of the generic stuff so I need to look more closely at that to see if it’s something we were relying upon which wasn’t actually true or some discrepancy between the two type systems. If I narrow it down and it’s not us, I’ll open separate defects for that.

I’ve noticed you’ve been full out at trying to get all of the issues reported with the types fixed quickly and have been very grateful for your work on that!

0reactions
sean-daleycommented, Mar 30, 2022

still HookNextFunction is missing please guid me if there is any solution for that .

I’m assuming you are using 6.x+ now? It was added back in the 5.x stream after this issue was closed but was removed from the 6.x code base per the migration document at https://mongoosejs.com/docs/migrating_to_6.html

We’ve worked around it by just defining it ourselves going forward like so:

// Mongoose used to define this before mongoose 6. For backward's compatibility, we will now just define it ourselves.
export interface HookNextFunction {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  (error?: Error): any
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

"this" and "next" in mongoose middleware with TS not working
I am trying to make middleware work with Typescript, but both this and next in pre and post are not working correctly, I...
Read more >
Migrating to Mongoose 6
The following legacy types have been removed: ModelUpdateOptions; DocumentQuery; HookSyncCallback; HookAsyncCallback; HookErrorCallback; HookNextFunction ...
Read more >
Working with Mongoose in TypeScript - The Code Barbarian
Hello, World. First, install the necessary packages: npm install mongoose typescript @types/mongoose. To get started with Mongoose, you should ...
Read more >
How to Migrate Mongoose from v5.x to v6.x - Morioh
When connected to a replica set, connections now emit 'disconnected' when connection to the primary is lost. In Mongoose 5, connections only ...
Read more >
Module '"mongoose"' has no exported member ... - YouTube
In this video, we fix an error related to DocumentDefinition and update service inputs so they do not need to omit values.
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