Skip to content

Commit 70466d0

Browse files
authored
Merge pull request #15794 from Automattic/vkarpov15/gh-15780
types(schema): allow calling schema.static() with `as TStatics`
2 parents 323f857 + 29fbcc1 commit 70466d0

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

test/types/queries.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,3 +826,17 @@ function gh15671() {
826826
};
827827
};
828828
}
829+
830+
async function gh15786() {
831+
interface IDoc {
832+
nmae: string;
833+
}
834+
835+
interface DocStatics {
836+
m1(): void;
837+
m2(): void;
838+
}
839+
840+
const schema = new Schema<IDoc, Model<IDoc>, {}, {}, {}, DocStatics>({});
841+
schema.static({ m1() {} } as DocStatics);
842+
}

types/index.d.ts

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

624624
/** Adds static "class" methods to Models compiled from this schema. */
625625
static<K extends keyof TStaticMethods>(name: K, fn: TStaticMethods[K]): this;
626+
static(obj: { [F in keyof TStaticMethods]: TStaticMethods[F] }): this;
626627
static(obj: { [F in keyof TStaticMethods]: TStaticMethods[F] } & { [name: string]: (this: TModelType, ...args: any[]) => any }): this;
627628
static(name: string, fn: (this: TModelType, ...args: any[]) => any): this;
628629

0 commit comments

Comments
 (0)