-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Could someone help explain/fix the type for Schema? #10308
Comments
The The reason for the 3rd generic arg is backwards compatibility. We'll add some more about this to our TypeScript docs. |
There might be a misunderstanding. I'm asking why my Omit example isn't superior (or something closer to it). My understanding from what you wrote is:
If a dev is using plugins, or future calls to add(), can't that be part of the dev's definition? Why would mongoose need to know about that? For that matter, you don't even need the To be clear (in reference to your first sentence), my example is what did make it complain if a field was missing in the schema; the current definition does not complain. |
Because we'd need to know all the paths to list in |
As I said, I don't understand why you would need that: Forget the constructor(definition?: {
[P in keyof DocType]: SchemaTypeOptions<DocType[P]>
}, options?: SchemaOptions); In your example, the above should work: 584e630#diff-4c048a457328a2cbcb214eba5e9c0639ab3b5cdb8710a57e251b31ccc774dde5 |
The current type is a somewhat more complex option of what you specified. Take a look at what Line 1263 in 7b51443
|
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node: 14.17.0
Mongoose: 5.12.10
Mongo: latest (docker image)
So I'm writing a Schema based on an interface
User
:My Schema is:
After looking through the type for the Schema class, I've realized I need to add a third generic to the UserSchema:
This is already a surprising interface; but that successfully reports errors for typos in fields. That's good, but it doesn't report if a field is missing.
Here's something close to what I would have expected for a type:
instead of what's currently there (https://github.com/Automattic/mongoose/blob/master/index.d.ts#L1103):
Which appears to be much more complicated, and I can't figure out why my suggested replacement wouldn't be much better. What am I missing? Wouldn't it be better to report if a field is missing? Why is the current type so convoluted and based on a third Generic being passed?
Any thoughts/comments would be much appreciated. Thanks!
The text was updated successfully, but these errors were encountered: