From a30ec7ea2d10ce53826a64d9775d8dac9cbaab0b Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 17 Aug 2017 14:31:30 -0700 Subject: [PATCH] Fix mongoose-promise and mpromise compatibility --- types/mongoose-promise/index.d.ts | 8 ++++---- types/mongoose-promise/mongoose-promise-tests.ts | 2 +- types/mpromise/index.d.ts | 15 +++------------ 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/types/mongoose-promise/index.d.ts b/types/mongoose-promise/index.d.ts index a5e75ea4ab..30becf8a2f 100644 --- a/types/mongoose-promise/index.d.ts +++ b/types/mongoose-promise/index.d.ts @@ -83,7 +83,7 @@ declare module 'mongoose' { * Rejects this promise with reason. * If the promise has already been fulfilled or rejected, not action is taken. */ - reject(reason: Object | string | Error): this; + reject(reason: any): this; /** * Resolves this promise to a rejected state if err is passed or a fulfilled state if no err is passed. @@ -93,15 +93,15 @@ declare module 'mongoose' { * @param err error or null * @param val value to fulfill the promise with */ - resolve(err?: any, val?: Object): this; + resolve(err?: any, ...args: T[]): this; /** * Creates a new promise and returns it. If onFulfill or onReject are passed, they are added as * SUCCESS/ERROR callbacks to this promise after the nextTick. * Conforms to promises/A+ specification. */ - then(onFulfill: (...args: T[]) => void | TRes | PromiseLike, - onReject?: (err: any) => void | TRes | PromiseLike): MongoosePromise; + then(onFulfill: (...values: T[]) => TRes | PromiseLike, + onReject?: (err: any) => TRes | PromiseLike): MongoosePromise; /** * Fulfills this promise with passed arguments. Alias of mpromise#fulfill. diff --git a/types/mongoose-promise/mongoose-promise-tests.ts b/types/mongoose-promise/mongoose-promise-tests.ts index f6e4aa115b..78a0a5729c 100644 --- a/types/mongoose-promise/mongoose-promise-tests.ts +++ b/types/mongoose-promise/mongoose-promise-tests.ts @@ -27,7 +27,7 @@ mongopromise.end(); mongopromise.error(999).error([]); mongopromise.on('init', cb).on('init', cb); mongopromise.reject({}).reject('').reject(new Error('hi')); -mongopromise.resolve(new Error('hi'), {}).resolve(); +mongopromise.resolve(new Error('hi'), 0); mongopromise.then(function (arg) { arg.toFixed(); return 9; diff --git a/types/mpromise/index.d.ts b/types/mpromise/index.d.ts index d7ab105f19..12f014054f 100644 --- a/types/mpromise/index.d.ts +++ b/types/mpromise/index.d.ts @@ -3,14 +3,6 @@ // Definitions by: Seulgi Kim // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -interface IFulfillFunction { - (...args: F[]): void; - (arg: F): void; -} -interface IRejectFunction { - (err: R): void; -} interface IResolveFunction { (err: R, ...args: F[]): void; (err: R, arg: F): void; @@ -23,16 +15,15 @@ declare class Promise { static SUCCESS: string; fulfill(...args: F[]): Promise; - fulfill(arg: F): Promise; reject(reason: R): Promise; resolve(reason: R, ...args: F[]): Promise; resolve(reason: R, arg: F): Promise; - onFulfill(callback: IFulfillFunction): Promise; - onReject(callback: IRejectFunction): Promise; + onFulfill(callback: (...args: F[]) => void): Promise; + onReject(callback: (err: R) => void): Promise; onResolve(callback: IResolveFunction): Promise; - then(onFulfilled: IFulfillFunction, onRejected?: IRejectFunction): Promise; + then(onFulfilled: (...values: F[]) => TRes | PromiseLike, onRejected?: (err: R) => TRes | PromiseLike): Promise; end(): void; chain(promise: Promise): Promise;