-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
fix: Strict Projection Object Typing #13993
fix: Strict Projection Object Typing #13993
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor comment, otherwise LGTM. Great work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of use cases I'd like to see tests for that don't look like this PR supports
- Allow adding fields that aren't in the schema to the projection
- Projection operators: $slice,
$elemMatch
- Dotted paths, like
'child.name': 1
- Using
$meta
with text search:score: { $meta: 'textScore' }
Will have to review some more to see if there are any other projection cases that we've missed
Another thing we'll need to make sure of: |
For using |
Test.find({}, { someOtherField: 1 }); // This should be allowed since it's not a field in the schema
interface X {
docs: { users: { name: string } }[]
}
type X = Projection<X>
const x: X = { 'docs.users': { name: 1 } } // now supports typing of this inner object and it suggests `name` |
@pshaddel great feature! type EntityA = { a: number, b: ... }
const a = A.findOne({}, { a: 1 }) // typeof a == { a: number } |
Thanks! Still working on this feature. My intention is to implement Query Return Type in another task after tackling this one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Will merge this into 8.1.
@pshaddel looks like I merged a bit too early, literally the next issue I looked at highlighted an issue with this PR 😞 . #3230 (comment) shows that Mongoose lets you deselect the discriminator key in an inclusive projection in addition to |
|
That's good, but it is still valid to add |
This reverts commit 6a88762.
OK |
@vkarpov15 do you know if this was ever reintroduced? I don't see a subsequent PR from @pshaddel If not, maybe it's worth reopening #13840 |
No further PR from my side, I think a test was failing because of some other changes. I can take a look. |
Just opened a new one: |
Summary
Fixes this issue: #13840
Examples