Skip to content

Commit

Permalink
fix(types): allow setting SchemaTypeOptions' index property to Inde…
Browse files Browse the repository at this point in the history
…xOptions

Fix #12562
  • Loading branch information
vkarpov15 committed Nov 4, 2022
1 parent 4ddeb46 commit ae14d0e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions test/types/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -872,3 +872,28 @@ function gh12431() {
type Example = InferSchemaType<typeof testSchema>;
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
}
}
);
}
2 changes: 1 addition & 1 deletion types/schematypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ae14d0e

Please sign in to comment.