From 1e79cac45b1b514577ff39b3f16666718e744628 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Fri, 8 Jan 2021 12:47:35 -0500 Subject: [PATCH] fix(index.d.ts): improve context and type bindings for `Schema#methods` and `Schema#statics` Fix #9717 --- index.d.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index.d.ts b/index.d.ts index 02ffecaa4c..9769a80ced 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1086,11 +1086,11 @@ declare module 'mongoose' { /** Adds an instance method to documents constructed from Models compiled from this schema. */ // eslint-disable-next-line @typescript-eslint/ban-types - method(name: string, fn: Function, opts?: any): this; - method(obj: { [name: string]: Function }): this; + method(name: string, fn: (this: DocType, ...args: any[]) => any, opts?: any): this; + method(obj: { [name: string]: (this: DocType, ...args: any[]) => any }): this; /** Object of currently defined methods on this schema. */ - methods: { [name: string]: (this: DocType, ...args: any[]) => void }; + methods: { [F in keyof DocType]: DocType[F] } & { [name: string]: (this: DocType, ...args: any[]) => any }; /** The original object passed to the schema constructor */ obj: any; @@ -1144,12 +1144,12 @@ declare module 'mongoose' { /** Adds static "class" methods to Models compiled from this schema. */ // eslint-disable-next-line @typescript-eslint/ban-types - static(name: string, fn: Function): this; + static(name: string, fn: (this: M, ...args: any[]) => any): this; // eslint-disable-next-line @typescript-eslint/ban-types - static(obj: { [name: string]: Function }): this; + static(obj: { [name: string]: (this: M, ...args: any[]) => any }): this; /** Object of currently defined statics on this schema. */ - statics: { [name: string]: Function }; + statics: { [F in keyof M]: M[F] } & { [name: string]: (this: M, ...args: any[]) => any }; /** Creates a virtual type with the given name. */ virtual(name: string, options?: any): VirtualType;