From a01ac1b2caf8a51d88ab2f8b05876429bb6656ae Mon Sep 17 00:00:00 2001 From: Matthew Bull Date: Tue, 20 Feb 2018 13:39:48 +0000 Subject: [PATCH] Correctly type fluent returns for extension --- types/agenda/agenda-tests.ts | 7 ++++++- types/agenda/index.d.ts | 18 +++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/types/agenda/agenda-tests.ts b/types/agenda/agenda-tests.ts index 5cd18baf76..bbf945bd62 100644 --- a/types/agenda/agenda-tests.ts +++ b/types/agenda/agenda-tests.ts @@ -1,10 +1,10 @@ import Agenda = require("agenda"); +import { Db, Server } from "mongodb"; var mongoConnectionString = "mongodb://127.0.0.1/agenda"; var agenda = new Agenda({ db: { address: mongoConnectionString } }); - agenda.define('delete old users', (job, done) => { }); @@ -102,4 +102,9 @@ job.remove(function(err) { if (!err) console.log("Successfully removed job from collection"); }) +class ExtendedAgenda extends Agenda { + async start() { } +} +const extendedAgenda: ExtendedAgenda = new ExtendedAgenda() + .mongo(new Db('some-database', new Server('host.name', 0))) diff --git a/types/agenda/index.d.ts b/types/agenda/index.d.ts index 426b187d7c..12b0b76c38 100644 --- a/types/agenda/index.d.ts +++ b/types/agenda/index.d.ts @@ -31,57 +31,57 @@ declare class Agenda extends EventEmitter { /** * Connect to the specified MongoDB server and database. */ - database(url: string, collection?: string, options?: any, cb?: ResultCallback): Agenda; + database(url: string, collection?: string, options?: any, cb?: ResultCallback): this; /** * Initialize agenda with an existing MongoDB connection. */ - mongo(db: Db, collection?: string, cb?: ResultCallback): Agenda; + mongo(db: Db, collection?: string, cb?: ResultCallback): this; /** * Sets the agenda name. */ - name(value: string): Agenda; + name(value: string): this; /** * Sets the interval with which the queue is checked. A number in milliseconds or a frequency string. */ - processEvery(interval: string | number): Agenda; + processEvery(interval: string | number): this; /** * Takes a number which specifies the max number of jobs that can be running at any given moment. By default it * is 20. * @param value The value to set. */ - maxConcurrency(value: number): Agenda; + maxConcurrency(value: number): this; /** * Takes a number which specifies the default number of a specific job that can be running at any given moment. * By default it is 5. * @param value The value to set. */ - defaultConcurrency(value: number): Agenda; + defaultConcurrency(value: number): this; /** * Takes a number shich specifies the max number jobs that can be locked at any given moment. By default it is * 0 for no max. * @param value The value to set. */ - lockLimit(value: number): Agenda; + lockLimit(value: number): this; /** * Takes a number which specifies the default number of a specific job that can be locked at any given moment. * By default it is 0 for no max. * @param value The value to set. */ - defaultLockLimit(value: number): Agenda; + defaultLockLimit(value: number): this; /** * Takes a number which specifies the default lock lifetime in milliseconds. By default it is 10 minutes. This * can be overridden by specifying the lockLifetime option to a defined job. * @param value The value to set. */ - defaultLockLifetime(value: number): Agenda; + defaultLockLifetime(value: number): this; /** * Returns an instance of a jobName with data. This does NOT save the job in the database. See below to learn