diff --git a/test/types/schema.test.ts b/test/types/schema.test.ts index 2ab4698e4b..b0e148afce 100644 --- a/test/types/schema.test.ts +++ b/test/types/schema.test.ts @@ -872,3 +872,28 @@ function gh12431() { type Example = InferSchemaType; expectType<{ testDate?: Date, testDecimal?: Types.Decimal128 }>({} as Example); } + +function gh12562() { + const emailRegExp = /@/; + const userSchema = new Schema( + { + email: { + type: String, + trim: true, + validate: { + validator: (value: string) => emailRegExp.test(value), + message: 'Email is not valid' + }, + index: { // uncomment the index object and for me trim was throwing an error + partialFilterExpression: { + email: { + $exists: true, + $ne: null + } + } + }, + select: false + } + } + ); +} diff --git a/types/schematypes.d.ts b/types/schematypes.d.ts index 899660d9fe..093651d140 100644 --- a/types/schematypes.d.ts +++ b/types/schematypes.d.ts @@ -100,7 +100,7 @@ declare module 'mongoose' { * If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose will * build an index on this path when the model is compiled. */ - index?: boolean | IndexDirection; + index?: boolean | IndexDirection | IndexOptions; /** * If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose