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

types: add UpdateQueryKnownOnly type for stricter UpdateQuery type checking #13699

Merged
merged 2 commits into from Aug 8, 2023

Conversation

vkarpov15
Copy link
Collaborator

Fix #13630

Summary

#13630 points out that there's no good way right now to enforce a more strict update syntax if you prefer to only allow known top-level keys in updates. This PR adds a separate UpdateQueryKnownOnly utility type for that. I'm not entirely convinced that this is useful or necessary, but it could be helpful in some cases. What do you think @hasezoey ?

Examples

Copy link
Collaborator

@hasezoey hasezoey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me for those that want stricter queries in types, though a example of how to apply the new type would be good

types/index.d.ts Show resolved Hide resolved
@hasezoey hasezoey added the typescript Types or Types-test related issue / Pull Request label Aug 4, 2023
Copy link
Collaborator

@AbdelrahmanHafez AbdelrahmanHafez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Would like to see more of stricter TS for filters/queries.
Can be challenging to apply for dot-separated paths though, but that's a good start!

@vkarpov15
Copy link
Collaborator Author

@AbdelrahmanHafez dot-separated paths is something we're unlikely to support in the foreseeable future. The MongoDB Node driver recently removed support for that because it caused a lot of problems; performance issues, and no way to stop infinite recursion in case of self-referential types. Unfortunately a limitation that we're gonna have to live with for now.

@vkarpov15 vkarpov15 merged commit 12ae677 into master Aug 8, 2023
3 checks passed
@vkarpov15 vkarpov15 added this to the 7.4.3 milestone Aug 8, 2023
@hasezoey hasezoey deleted the vkarpov15/gh-13630 branch August 8, 2023 19:18
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

Successfully merging this pull request may close these issues.

Definition of type UpdateQuery is not very accurate cause code hint not work
3 participants