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

(Bug) Type definitions: new signature for cursor.eachAsync() results in non-inferrable type arguments #10135

Closed
lincolnthree opened this issue Apr 14, 2021 · 1 comment
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@lincolnthree
Copy link

lincolnthree commented Apr 14, 2021

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

What is the current behavior?

Upgraded: mongoose ^5.11.14 → ^5.12.3

After upgrading to 5.12.x, Compilation fails when using the Cursor.eachAsync() method with (previously) valid type arguments:

image

image

Property 'id' does not exist on type '(TournamentResultSchemaV1 & Document<any, {}>) | [TournamentResultSchemaV1 & Document<any, {}>]'.
  Property 'id' does not exist on type '[TournamentResultSchemaV1 & Document<any, {}>]'.ts(2339)

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

  1. Call the cursor API and attempt to reference an instance as a non-array type.

What is the expected behavior?

The type should be narrowed based on the method signature used. If not using batch processing, the type should not be an Array type (or an optional array type).

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

5.12.3

This was changed in #9902 afaik, and results in a breaking API change as compilation fails with what used to be proper usage of the eachAsync API.

@IslandRhythms IslandRhythms 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 Apr 14, 2021
@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 Apr 19, 2021
@vkarpov15 vkarpov15 added this to the 5.12.6 milestone Apr 19, 2021
@lincolnthree
Copy link
Author

Thank you @vkarpov15!

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

3 participants