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

Improve types #9959

Merged
merged 2 commits into from
Feb 22, 2021
Merged

Improve types #9959

merged 2 commits into from
Feb 22, 2021

Conversation

btd
Copy link

@btd btd commented Feb 21, 2021

Summary

After 5.11 mongoose started to provide its own types. Some parts of types still use `any (compare the same places with @types/mongoose e.g)

Examples

  const { deletedCount } = await Model.deleteMany({ fieldFromModel });

while with some tsconfig settings tsc will not complain. But you will need to do the same for typescript-eslint.

@btd btd changed the title Improve types of Model.deleteMany and Model.deleteOne Improve types Feb 21, 2021
@btd
Copy link
Author

btd commented Feb 21, 2021

Also question why Document defined type of key as any and not ObjectId?

Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@vkarpov15
Copy link
Collaborator

Can you please clarify what you mean by "Also question why Document defined type of key as any and not ObjectId?"

@vkarpov15 vkarpov15 added this to the 5.11.18 milestone Feb 22, 2021
@vkarpov15 vkarpov15 added the typescript Types or Types-test related issue / Pull Request label Feb 22, 2021
@vkarpov15 vkarpov15 merged commit 09c3850 into Automattic:master Feb 22, 2021
@btd
Copy link
Author

btd commented Feb 22, 2021

@vkarpov15 on this line https://github.com/Automattic/mongoose/blob/master/index.d.ts#L369 Document defined as Document<T = any>. Why it is not ObjectId? I do not have problem with this now, just interested.

@vkarpov15
Copy link
Collaborator

Because _id can be any type. Nothing wrong with saying new Schema({ _id: Number })

This was referenced Mar 5, 2021
This was referenced Mar 12, 2021
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.

2 participants