diff --git a/test/types/schema.test.ts b/test/types/schema.test.ts index 04828bc4f1..5a399a0c7d 100644 --- a/test/types/schema.test.ts +++ b/test/types/schema.test.ts @@ -1634,3 +1634,7 @@ function gh14825() { type SchemaType = InferSchemaType; expectAssignable({} as SchemaType); } + +function gh14879() { + Schema.Types.String.setters.push((val?: unknown) => typeof val === 'string' ? val.trim() : val); +} diff --git a/types/schematypes.d.ts b/types/schematypes.d.ts index e8a0ecffdf..f5ca8ec0da 100644 --- a/types/schematypes.d.ts +++ b/types/schematypes.d.ts @@ -216,6 +216,9 @@ declare module 'mongoose' { /** Attaches a getter for all instances of this schema type. */ static get(getter: (value: any) => any): void; + /** Array containing default setters for all instances of this SchemaType */ + static setters: ((val?: unknown, priorVal?: unknown, doc?: Document, options?: Record | null) => unknown)[]; + /** The class that Mongoose uses internally to instantiate this SchemaType's `options` property. */ OptionsConstructor: SchemaTypeOptions;