-
-
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
InterSchemaType does not properly infer "required" field for Schema.Types.ObjectId type #12205
Comments
What is inferModelType suppose to be? |
@IslandRhythms Sorry it was a typo. I meant |
|
@darwin403 has meant the following: const campaignSchema = new Schema(
{
client: {
type: Schema.Types.ObjectId,
trim: true,
ref: 'User',
required: true
}
},
{ timestamps: true }
);
type ICampaign = InferSchemaType<typeof campaignSchema>; |
Yes, it returns a wrong result. |
…* to work around TS type inference issues Fix #12205
I can see the issue is in progress already, but just to confirm I have a similar issue even without specifying
Produces the following (notice Removing |
feat(types+schema): allow defining schema paths using mongoose.Types.* to work around TS type inference issues
Prerequisites
Mongoose version
^6.5.0
Node.js version
16.13.1
MongoDB server version
6.x
Description
A schema field with
{type: Schema.Types.ObjectId, required: true}
cause faulty inference of Schema type. But,{type: Schema.Types.ObjectId, required: false}
,{type: String, required: true}
seem to workSteps to Reproduce
The following works:
The following doesn't work:
Expected Behavior
The text was updated successfully, but these errors were encountered: