Skip to content

Commit

Permalink
Merge pull request #14881 from Automattic/vkarpov15/gh-14879
Browse files Browse the repository at this point in the history
types: make SchemaType static `setters` property accessible in TypeScript
  • Loading branch information
vkarpov15 authored Sep 11, 2024
2 parents 36fa0c0 + 60541e7 commit dd7e75e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/types/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1634,3 +1634,7 @@ function gh14825() {
type SchemaType = InferSchemaType<typeof schema>;
expectAssignable<User>({} as SchemaType);
}

function gh14879() {
Schema.Types.String.setters.push((val?: unknown) => typeof val === 'string' ? val.trim() : val);
}
3 changes: 3 additions & 0 deletions types/schematypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown>, options?: Record<string, any> | null) => unknown)[];

/** The class that Mongoose uses internally to instantiate this SchemaType's `options` property. */
OptionsConstructor: SchemaTypeOptions<T>;

Expand Down

0 comments on commit dd7e75e

Please sign in to comment.