-
-
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
typescript: Allow null for optional document fields #12781
Conversation
Accidently closed. Null has a special meaning in mongo. I doubt if this is a desired behavior. |
We can insert |
Nobody says that null is not a valid input. But while JSON.stringify removes keys with value null, the bson serializer serializes null values. So we should keep this in mind when merging this. |
I think it is the opposite actually. JSON.stringify() removes undefined keys, but keeps null keys: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#description |
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.
This works, thank you for making this change. You are correct that you can set any non-required property to null
.
My only concern is that this change might be a bit heavy for a patch release, so we'll save it for our next minor release.
It turns out what I really need for my use case is for optional strings to infer as So feel free to merge or not merge this PR, but I no longer have a stake in this issue now. Thanks for reviewing either way. |
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.
Merging into 6.9
Summary
When inferring types, allow
null
as well asundefined
if the field is optional.Fixes #12748
Examples