-
-
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
InferSchemaType: Allow null for optional fields #12748
Labels
typescript
Types or Types-test related issue / Pull Request
Milestone
Comments
@vkarpov15 I'm happy to help implement this change if you can give me a pointer of where to edit. I tried looking in https://github.com/Automattic/mongoose/blob/master/types/inferschematype.d.ts but couldn't find how we type optional fields. |
Yes, this is causing bugs for us. null is entirely different from undefined (trivially, null can be understood as intentionally set to nothing) |
vkarpov15
added a commit
that referenced
this issue
Sep 26, 2023
vkarpov15
added a commit
that referenced
this issue
Oct 4, 2023
vkarpov15
added a commit
that referenced
this issue
Oct 4, 2023
BREAKING CHANGE: allow null for optional fields in TypeScript
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prerequisites
Mongoose version
6.7.5
Node.js version
16.17.1
MongoDB server version
4.4
Typescript version (if applicable)
No response
Description
Currently optional fields in schemas accept either the field type or undefined. Can we change this to also accept
null
? AFAIKnull
should be treated the same asundefined
in this case, and it makes the types more usable. In our codebase, we generally treatnull
andundefined
the same in our types, unless we're forced to do otherwise due to explicit behavior difference such as https://mongoosejs.com/docs/migrating_to_6.html#removed-omitundefined.i.e. we are using
Steps to Reproduce
If I define the following schema:
It infers the following type:
Can we change this to
example?: string | null | undefined
?Expected Behavior
No response
The text was updated successfully, but these errors were encountered: