diff --git a/mongoose/mongoose-tests.ts b/mongoose/mongoose-tests.ts index 2f6467437c..cd5f53c4d9 100644 --- a/mongoose/mongoose-tests.ts +++ b/mongoose/mongoose-tests.ts @@ -369,7 +369,7 @@ schema.path('name'); schema.path('name', Number); schema.pathType('name'); schema.plugin(function() {}); -schema.post('save', function(doc: IActor) {}); +schema.post('save', function(next: () => void, doc: IActor) {}); schema.pre('save', function(next: () => void) {}); schema.requiredPaths(); schema.static('findByName', function(name: string, callback: () => void) {}); diff --git a/mongoose/mongoose.d.ts b/mongoose/mongoose.d.ts index ec785e4ffb..6d74a0e4b1 100644 --- a/mongoose/mongoose.d.ts +++ b/mongoose/mongoose.d.ts @@ -256,6 +256,10 @@ declare module "mongoose" { OId: Types.ObjectId; Mixed: any; }; + + methods: any; + statics: any; + constructor(schema?: Object, options?: Object); add(obj: Object, prefix?: string): void; @@ -269,14 +273,43 @@ declare module "mongoose" { path(path: string, constructor: any): Schema; pathType(path: string): string; plugin(plugin: (schema: Schema, options?: Object) => void, options?: Object): Schema; - post(method: string, fn: Function): Schema; - pre(method: string, callback: Function): Schema; + + pre(method: string, fn: HookSyncCallback, errorCb?: HookErrorCallback): Schema; + pre(method: string, isAsync: boolean, fn: HookAsyncCallback, errorCb?: HookErrorCallback): Schema; + post(method: string, fn: HookSyncCallback, errorCb?: HookErrorCallback): Schema; + post(method: string, isAsync: boolean, fn: HookAsyncCallback, errorCb?: HookErrorCallback): Schema; + requiredPaths(): string[]; set(key: string, value: any): void; static(name: string, fn: Function): Schema; virtual(name: string, options?: Object): VirtualType; virtualpath(name: string): VirtualType; + } + + // hook functions: https://github.com/vkarpov15/hooks-fixed + export interface HookSyncCallback { + (next: HookNextFunction, ...hookArgs:any[]): any; + } + + export interface HookAsyncCallback { + (next: HookNextFunction, done: HookDoneFunction, ...hookArgs:any[]): any; + } + + export interface HookErrorCallback { + (error: Error): any; + } + + export interface HookNextFunction { + (error: Error): any; + (...hookArgs:any[]): any; + } + + export interface HookDoneFunction { + (error: Error): any; + (...hookArgs:any[]): any; + } + export interface SchemaOption { autoIndex?: boolean; bufferCommands?: boolean;