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(model+query): use stricter typings for updateX(), replaceOne(),deleteX() Model functions #14228

Merged
merged 3 commits into from Jan 3, 2024

Conversation

vkarpov15
Copy link
Collaborator

Fix #14204

Summary

While Mongoose's current options typings are technically correct because of chaining, using stricter types in the Model functions that return a query lines up better with how developers use it. Plus with [other: string]: any, devs can still use other options.

I only made these changes for deleteX(), replaceOne(), and updateX() because Mongoose's QueryOptions has a projection property that doesn't line up exactly with the MongoDB Node driver's: the MongoDB Node driver's projection type is just Record<string, any>, doesn't take into account schema definitions.

Examples

types/query.d.ts Show resolved Hide resolved
types/query.d.ts Show resolved Hide resolved
types/models.d.ts Outdated Show resolved Hide resolved
@hasezoey hasezoey added the typescript Types or Types-test related issue / Pull Request label Jan 2, 2024
@vkarpov15 vkarpov15 added this to the 8.0.4 milestone Jan 3, 2024
@vkarpov15 vkarpov15 merged commit 8a06572 into master Jan 3, 2024
3 checks passed
@vkarpov15 vkarpov15 deleted the vkarpov15/gh-14204 branch January 3, 2024 20:45
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.

Type definition for Query.updateOne is wrong - options such as new are not supported by Mongo
2 participants