-
Notifications
You must be signed in to change notification settings - Fork 29.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
@types/mongoose create schema forces non-required properties at crate time #45608
Comments
Proper usage here is: type CreateDocument = Omit<IDocument, "addedInMiddleware">;
model.create<CreateDocument>({}); Or define your interface like: interface IDocument extends Mongoose.Document {
addedInMiddleware?: string
} |
Sorry, neither of your suggestions are proper usage.
This will NOT work for nested objects.
This is just wrong. |
This reverts the (second) attempt made at adding schema for document creation because it causes valid well-typed code to break. The previous attempt was made at: DefinitelyTyped@26587aa#diff-f77e4c92e873042528b4ef79285cdf3c And reverted at: DefinitelyTyped@c860c1d#diff-f77e4c92e873042528b4ef79285cdf3c This attempt suffers from the same faults as the previous attempt and causes valid, well-typed, code to break which should never happen in a types library. Some of them are listed here in the previous PR I made to remove this type checking DefinitelyTyped#37823 fixes DefinitelyTyped#45305 fixes DefinitelyTyped#45609 fixes DefinitelyTyped#45608 revert 88a54a9
interface IDocument extends Mongoose.Document {
readonly addedInMiddleware: string
} This will also work if it's read only, meaning |
This reverts the (second) attempt made at adding schema for document creation because it causes valid well-typed code to break. The previous attempt was made at: DefinitelyTyped@26587aa#diff-f77e4c92e873042528b4ef79285cdf3c And reverted at: DefinitelyTyped@c860c1d#diff-f77e4c92e873042528b4ef79285cdf3c This attempt suffers from the same faults as the previous attempt and causes valid, well-typed, code to break which should never happen in a types library. Some of them are listed here in the previous PR I made to remove this type checking DefinitelyTyped#37823 fixes DefinitelyTyped#45305 fixes DefinitelyTyped#45609 fixes DefinitelyTyped#45608 revert 88a54a9
Of course it will, you can override the type at any level in the schema. Here's a helper type to help with that: |
This reverts the (second) attempt made at adding schema for document creation because it causes valid well-typed code to break. The previous attempt was made at: DefinitelyTyped@26587aa#diff-f77e4c92e873042528b4ef79285cdf3c And reverted at: DefinitelyTyped@c860c1d#diff-f77e4c92e873042528b4ef79285cdf3c This attempt suffers from the same faults as the previous attempt and causes valid, well-typed, code to break which should never happen in a types library. Some of them are listed here in the previous PR I made to remove this type checking DefinitelyTyped#37823 fixes DefinitelyTyped#45305 fixes DefinitelyTyped#45609 fixes DefinitelyTyped#45608 revert 88a54a9
This reverts the (second) attempt made at adding schema for document creation because it causes valid well-typed code to break. The previous attempt was made at: DefinitelyTyped@26587aa#diff-f77e4c92e873042528b4ef79285cdf3c And reverted at: DefinitelyTyped@c860c1d#diff-f77e4c92e873042528b4ef79285cdf3c This attempt suffers from the same faults as the previous attempt and causes valid, well-typed, code to break which should never happen in a types library. Some of them are listed here in the previous PR I made to remove this type checking DefinitelyTyped#37823 fixes DefinitelyTyped#45305 fixes DefinitelyTyped#45609 fixes DefinitelyTyped#45608 revert 88a54a9
This reverts the (second) attempt made at adding schema for document creation because it causes valid well-typed code to break. The previous attempt was made at: DefinitelyTyped@26587aa#diff-f77e4c92e873042528b4ef79285cdf3c And reverted at: DefinitelyTyped@c860c1d#diff-f77e4c92e873042528b4ef79285cdf3c This attempt suffers from the same faults as the previous attempt and causes valid, well-typed, code to break which should never happen in a types library. Some of them are listed here in the previous PR I made to remove this type checking DefinitelyTyped#37823 fixes DefinitelyTyped#45305 fixes DefinitelyTyped#45609 fixes DefinitelyTyped#45608 revert 88a54a9
Hi thread, we're moving DefinitelyTyped to use GitHub Discussions for conversations the To help with the transition, we're closing all issues which haven't had activity in the last 6 months, which includes this issue. If you think closing this issue is a mistake, please pop into the TypeScript Community Discord and mention the issue in the |
@types/mongoose
package and had problems.Definitions by:
inindex.d.ts
) so they can respond.In the example below,
addedInMiddleware
is required on the document but not on the create schema since it's added in a middleware.The schema added in 88a54a9 causes
addedInMiddleware
to be required at compile time, but it shouldn't be.@andreialecu I'd appreciate if you can fix this.
The text was updated successfully, but these errors were encountered: