From c0fc0677a3a95a4694f4c99276ecfc6c54eac9ad Mon Sep 17 00:00:00 2001 From: Silas Rech Date: Fri, 22 Mar 2019 14:43:44 +0100 Subject: [PATCH] [bull] add function overloading --- types/bull/index.d.ts | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/types/bull/index.d.ts b/types/bull/index.d.ts index 5297eadb19..07de38e05d 100644 --- a/types/bull/index.d.ts +++ b/types/bull/index.d.ts @@ -13,6 +13,7 @@ // Dan Manastireanu // Kjell-Morten Bratsberg Thorsen // Christian D. +// Silas Rech // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -114,6 +115,9 @@ declare namespace Bull { type JobId = number | string; + type ProcessCallbackFunction = (job: Job, done: DoneCallback) => void; + type ProcessPromiseFunction = (job: Job) => Promise; + interface Job { id: JobId; @@ -397,6 +401,8 @@ declare namespace Bull { */ isReady(): Promise; + /* tslint:disable:unified-signatures */ + /** * Defines a processing function for the jobs placed into a given Queue. * @@ -414,7 +420,9 @@ declare namespace Bull { * If the promise is rejected, the error will be passed as a second argument to the "failed" event. * If it is resolved, its value will be the "completed" event's second argument. */ - process(callback: ((job: Job, done: DoneCallback) => void) | ((job: Job) => Promise) | string): void; + process(callback: ProcessCallbackFunction): void; + process(callback: ProcessPromiseFunction): void; + process(callback: string): void; /** * Defines a processing function for the jobs placed into a given Queue. @@ -435,7 +443,9 @@ declare namespace Bull { * * @param concurrency Bull will then call your handler in parallel respecting this maximum value. */ - process(concurrency: number, callback: ((job: Job, done: DoneCallback) => void) | ((job: Job) => Promise) | string): void; + process(concurrency: number, callback: ProcessCallbackFunction): void; + process(concurrency: number, callback: ProcessPromiseFunction): void; + process(concurrency: number, callback: string): void; /** * Defines a processing function for the jobs placed into a given Queue. @@ -456,8 +466,9 @@ declare namespace Bull { * * @param name Bull will only call the handler if the job name matches */ - // tslint:disable-next-line:unified-signatures - process(name: string, callback: ((job: Job, done: DoneCallback) => void) | ((job: Job) => Promise) | string): void; + process(name: string, callback: ProcessCallbackFunction): void; + process(name: string, callback: ProcessPromiseFunction): void; + process(name: string, callback: string): void; /** * Defines a processing function for the jobs placed into a given Queue. @@ -479,7 +490,11 @@ declare namespace Bull { * @param name Bull will only call the handler if the job name matches * @param concurrency Bull will then call your handler in parallel respecting this maximum value. */ - process(name: string, concurrency: number, callback: ((job: Job, done: DoneCallback) => void) | ((job: Job) => Promise) | string): void; + process(name: string, concurrency: number, callback: ProcessCallbackFunction): void; + process(name: string, concurrency: number, callback: ProcessPromiseFunction): void; + process(name: string, concurrency: number, callback: string): void; + + /* tslint:enable:unified-signatures */ /** * Creates a new job and adds it to the queue. @@ -598,7 +613,7 @@ declare namespace Bull { * Returns a promise that will return an array of job instances of the given types. * Optional parameters for range and ordering are provided. */ - getJobs(types: string[], start?: number, end?: number, asc?: boolean): Promise; + getJobs(types: string[], start?: number, end?: number, asc?: boolean): Promise>>; /** * Returns a promise that resolves with the job counts for the given queue.