You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do you want to request a feature or report a bug?
Suggest solution for a feature
What is the current behavior?
Projection is not typed at all
What is the expected behavior?
To be at least somehow typed
Hello. I'd like to propose a small improvement to have typed projection for the simplest cases. Talking about cases where you use findById(id, { something: 1 }), basically you just use 1 or true.
I would change the type definition of find queries to this
What it does is that if you decide to use the project parameter in find queries and you want to use simple selects, the result type will only include the properties that you selected. If it's not a simple select (eg { something: "$xx" }), it would just return any.
what do you think?
Note: To use 1 instead of true means, that the project object would need to be marked as const.. like this Model.findById(id, { name: 1 } as const)
The text was updated successfully, but these errors were encountered:
vkarpov15
added
typescript
Types or Types-test related issue / Pull Request
and removed
new feature
This change adds new functionality, like a new method or class
labels
Jan 3, 2022
I like the idea of allowing overriding the return type of a query, but I think the suggested API is not viable because (1) it is backwards breaking, and (2) doesn't support exclusive projections. Better to just allow findById<Pick<User, 'name'>>(id, { name: 1 }).
Do you want to request a feature or report a bug?
Suggest solution for a feature
What is the current behavior?
Projection is not typed at all
What is the expected behavior?
To be at least somehow typed
Hello. I'd like to propose a small improvement to have typed projection for the simplest cases. Talking about cases where you use
findById(id, { something: 1 })
, basically you just use1
ortrue
.I would change the type definition of
find
queries to thisWhat it does is that if you decide to use the
project
parameter infind
queries and you want to use simple selects, the result type will only include the properties that you selected. If it's not a simple select (eg{ something: "$xx" }
), it would just return any.what do you think?
Note: To use
1
instead oftrue
means, that the project object would need to be marked as const.. like thisModel.findById(id, { name: 1 } as const)
The text was updated successfully, but these errors were encountered: