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

docs: add schema type widening advice #14790

Merged
merged 1 commit into from
Aug 7, 2024
Merged

docs: add schema type widening advice #14790

merged 1 commit into from
Aug 7, 2024

Conversation

JstnMcBrd
Copy link
Contributor

Summary

While using Mongoose with TypeScript, @ShunnShine and I discovered the dangers of defining the schema in a separate variable when we realized all of our fields with required: false were being treated as required: true.

We eventually figured out how to fix the type definitions by using as const.

We looked at the Schemas in TypeScript documentation and saw a warning about assigning a schema to a temporary variable (fair enough), but did not see any information about using as const, even though it is used in the example code right below - without explanation.

This PR adds a little section about type widening and as const to help users understand why this was done.

@hasezoey hasezoey added the docs This issue is due to a mistake or omission in the mongoosejs.com documentation label Aug 6, 2024
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.

Thanks 👍

@vkarpov15 vkarpov15 added this to the 8.5.3 milestone Aug 7, 2024
@vkarpov15 vkarpov15 merged commit 8575b9c into Automattic:master Aug 7, 2024
2 checks passed
@JstnMcBrd JstnMcBrd deleted the mcb/as-const branch August 8, 2024 04:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This issue is due to a mistake or omission in the mongoosejs.com documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants