-
-
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
Issue with typings on SchemaDefinition #9857
Comments
There are several things going on here, sorry if this gets a little long. First, the type parameter of mongoose.Document doesn't set the type of user-defined properties on instances of Document. It sets the type of the document's Second, the Typescript types as currently written don't allow you to reliably infer the type of a SchemaDefinition from the type of a user-defined interface. It seems like the following works:
However, it only works in the sense that it doesn't throw a compiler error. As @amorimfilipe noticed, the compiler will allow some obviously incorrect values for the keys of Lastly, note that the type of IMO, these types don't work as expected. However, it's pretty easy to avoid dealing with these intermediate types and still get a typesafe model to work with in the rest of your program by doing something like this. You can also do the following to fix the compiler error you noted in Behavior A:
Note that the above still doesn't prevent passing bogus values in
still typechecks. |
@Rossh87 Thanks for the insight. |
Do you want to request a feature or report a bug?
Not sure if it is a bug or a question.
What is the current behavior?
Behavior A
if add
boolean | number | date
totype SchemaDefinitionProperty
it don't gives an error.Behavior B
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
The text was updated successfully, but these errors were encountered: