Skip to content

Commit dd7e75e

Browse files
authored
Merge pull request #14881 from Automattic/vkarpov15/gh-14879
types: make SchemaType static `setters` property accessible in TypeScript
2 parents 36fa0c0 + 60541e7 commit dd7e75e

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: ((val?: unknown, priorVal?: unknown, doc?: Document<unknown>, options?: Record<string, any> | null) => unknown)[];
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)