Skip to content

Commit c7f7273

Browse files
committed
types: make SchemaType static setters property accessible in TypeScript
Fix #14879
1 parent 286ab98 commit c7f7273

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

test/types/schema.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,3 +1634,7 @@ function gh14825() {
16341634
type SchemaType = InferSchemaType<typeof schema>;
16351635
expectAssignable<User>({} as SchemaType);
16361636
}
1637+
1638+
function gh14879() {
1639+
Schema.Types.String.setters.push((val?: unknown) => typeof val === 'string' ? val.trim() : val);
1640+
}

types/schematypes.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ declare module 'mongoose' {
216216
/** Attaches a getter for all instances of this schema type. */
217217
static get(getter: (value: any) => any): void;
218218

219+
/** Array containing default setters for all instances of this SchemaType */
220+
static setters: Function[];
221+
219222
/** The class that Mongoose uses internally to instantiate this SchemaType's `options` property. */
220223
OptionsConstructor: SchemaTypeOptions<T>;
221224

0 commit comments

Comments
 (0)