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

Type the projection parameter and narrow return type when used #11458

Closed
almeidx opened this issue Feb 27, 2022 · 1 comment
Closed

Type the projection parameter and narrow return type when used #11458

almeidx opened this issue Feb 27, 2022 · 1 comment

Comments

@almeidx
Copy link

almeidx commented Feb 27, 2022

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

What is the current behavior?
The projection parameter on methods such as findOne(), findById(), etc., is typed as any and doesn't narrow the return type
(This is just a typings QOL improvement request, not related to runtime behaviour)

If the current behavior is a bug, please provide the steps to reproduce.
I wouldn't say this is necessarily a bug, but here's an example of what I'm suggesting:
https://gist.github.com/almeidx/74ede05cdebc1ba4a6fdfb0c03814eb9
This also includes a workaround that I have been using

What is the expected behavior?
I expected the projection parameter to be typed as the document's keys, and I would expect the return type to be narrowed down accordingly

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node v17.4.0
Mongoose v6.2.3
TypeScript 4.5.5

@IslandRhythms IslandRhythms added the new feature This change adds new functionality, like a new method or class label Feb 28, 2022
@AbdelrahmanHafez AbdelrahmanHafez added duplicate and removed new feature This change adds new functionality, like a new method or class labels Feb 28, 2022
@AbdelrahmanHafez
Copy link
Collaborator

Hello @almeidx, this is a duplicate of #11437. Let's follow up there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants