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

TS/ESlint: pre hook returning a Promise #10229

Closed
qqilihq opened this issue May 10, 2021 · 2 comments
Closed

TS/ESlint: pre hook returning a Promise #10229

qqilihq opened this issue May 10, 2021 · 2 comments
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@qqilihq
Copy link

qqilihq commented May 10, 2021

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

Bug?

What is the current behavior?

We just updated to the latest Mongoose version 5.12.8 and got rid of the @types/mongoose. We had a couple of pre save hooks which used an async function. This has worked fine so far (i.e. compiled via TypeScript and verified working at runtime).

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

Since using Mongoose’s typings, the following code produces an ESLint error:

// PRODUCES ESLINT ERROR:
// Promise returned in function argument where a void return was expected.eslint
// @typescript-eslint/no-misused-promises
mySchema.pre('save', async function () {
   // some async function returning a Promise
});

What is the expected behavior?

I assume that it’s valid behavior to return a Promise (as stated, Mongoose handled this fine in the past). So the typings should include the case of returning a Promise<void> instead of void, so that the linting passes.

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

  • Mongoose 5.12.8
  • ESLint with plugin:promise/recommended
@vkarpov15 vkarpov15 added this to the 5.12.9 milestone May 10, 2021
@vkarpov15 vkarpov15 added typescript Types or Types-test related issue / Pull Request needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue labels May 10, 2021
@vkarpov15
Copy link
Collaborator

Thanks for reporting, we'll look into this and fix over the next couple of days if we can confirm this is a bug.

@qqilihq
Copy link
Author

qqilihq commented May 10, 2021

Great, thanks! Let me know if I can help with a reproduction!

@vkarpov15 vkarpov15 removed the needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue label May 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typescript Types or Types-test related issue / Pull Request
Projects
None yet
Development

No branches or pull requests

2 participants