Skip to content

Commit b635f4e

Browse files
committed
types(schema): allow calling schema.static() with as TStatics
Re: #15780
1 parent 2decab7 commit b635f4e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

test/types/queries.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,3 +798,16 @@ function gh15671() {
798798
};
799799
};
800800
}
801+
802+
async function gh15786() {
803+
interface IDoc {
804+
}
805+
806+
interface DocStatics {
807+
m1(): void;
808+
m2(): void;
809+
}
810+
811+
const schema = new Schema<IDoc, Model<IDoc>, {}, {}, {}, DocStatics>({});
812+
schema.static({ m1() {} } as DocStatics);
813+
}

types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ declare module 'mongoose' {
542542

543543
/** Adds static "class" methods to Models compiled from this schema. */
544544
static<K extends keyof TStaticMethods>(name: K, fn: TStaticMethods[K]): this;
545+
static(obj: { [F in keyof TStaticMethods]: TStaticMethods[F] }): this;
545546
static(obj: { [F in keyof TStaticMethods]: TStaticMethods[F] } & { [name: string]: (this: TModelType, ...args: any[]) => any }): this;
546547
static(name: string, fn: (this: TModelType, ...args: any[]) => any): this;
547548

0 commit comments

Comments
 (0)