Fix mongoose-promise and mpromise compatibility

This commit is contained in:
Andy Hanson
2017-08-17 14:31:30 -07:00
parent bdeaabff24
commit a30ec7ea2d
3 changed files with 8 additions and 17 deletions

View File

@@ -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<TRes>(onFulfill: (...args: T[]) => void | TRes | PromiseLike<TRes>,
onReject?: (err: any) => void | TRes | PromiseLike<TRes>): MongoosePromise<TRes>;
then<TRes>(onFulfill: (...values: T[]) => TRes | PromiseLike<TRes>,
onReject?: (err: any) => TRes | PromiseLike<TRes>): MongoosePromise<TRes>;
/**
* Fulfills this promise with passed arguments. Alias of mpromise#fulfill.

View File

@@ -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;

View File

@@ -3,14 +3,6 @@
// Definitions by: Seulgi Kim <https://github.com/sgkim126/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
interface IFulfillFunction<F> {
(...args: F[]): void;
(arg: F): void;
}
interface IRejectFunction<R> {
(err: R): void;
}
interface IResolveFunction<F, R> {
(err: R, ...args: F[]): void;
(err: R, arg: F): void;
@@ -23,16 +15,15 @@ declare class Promise<F, R> {
static SUCCESS: string;
fulfill(...args: F[]): Promise<F, R>;
fulfill(arg: F): Promise<F, R>;
reject(reason: R): Promise<F, R>;
resolve(reason: R, ...args: F[]): Promise<F, R>;
resolve(reason: R, arg: F): Promise<F, R>;
onFulfill(callback: IFulfillFunction<F>): Promise<F, R>;
onReject(callback: IRejectFunction<R>): Promise<F, R>;
onFulfill(callback: (...args: F[]) => void): Promise<F, R>;
onReject(callback: (err: R) => void): Promise<F, R>;
onResolve(callback: IResolveFunction<F, R>): Promise<F, R>;
then<F, R>(onFulfilled: IFulfillFunction<F>, onRejected?: IRejectFunction<R>): Promise<F, R>;
then<TRes>(onFulfilled: (...values: F[]) => TRes | PromiseLike<TRes>, onRejected?: (err: R) => TRes | PromiseLike<TRes>): Promise<TRes, R>;
end(): void;
chain(promise: Promise<F, R>): Promise<F, R>;