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

HookNextFunction missing from local types? #9653

Closed
sean-daley opened this issue Dec 4, 2020 · 6 comments
Closed

HookNextFunction missing from local types? #9653

sean-daley opened this issue Dec 4, 2020 · 6 comments
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@sean-daley
Copy link

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.

@vkarpov15
Copy link
Collaborator

We tried to avoid breaking changes where possible, however, we didn't feel that HookNextFunction is a useful type. We're definitely open to the possibility that we're wrong in that assumption though. Is this causing some problems for you?

@vkarpov15 vkarpov15 added this to the 5.11.4 milestone Dec 4, 2020
@vkarpov15 vkarpov15 added the typescript Types or Types-test related issue / Pull Request label Dec 4, 2020
@vkarpov15 vkarpov15 modified the milestones: 5.11.4, 5.11.5 Dec 4, 2020
@sean-daley
Copy link
Author

We tried to avoid breaking changes where possible, however, we didn't feel that HookNextFunction is a useful type. We're definitely open to the possibility that we're wrong in that assumption though. Is this causing some problems for you?

Well, it being missing is causing compilation errors for us. We weren't really expecting to have to fix our code this much after upgrading to a new minor release but if the plan is to not bring those definitions back, we will just update our code accordingly. Thanks.

@vkarpov15
Copy link
Collaborator

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?

@sean-daley
Copy link
Author

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!

@arunsingh28
Copy link

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

@sean-daley
Copy link
Author

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
}

@Automattic Automattic locked and limited conversation to collaborators Apr 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
typescript Types or Types-test related issue / Pull Request
Projects
None yet
Development

No branches or pull requests

3 participants