From ed5fcefc9cd9e5e5d9a71138ffde62f88a5eed64 Mon Sep 17 00:00:00 2001 From: Andrew Webb Date: Tue, 23 Apr 2019 21:08:02 +0200 Subject: [PATCH] Expand hubot typings (#34916) * Expand hubot typings * Fix build issue * Fix tests for mattvperrys hubot pr * Update mattvperrys code after rebase * Remove redundant line --- types/hubot/hubot-tests.ts | 12 ++++++++---- types/hubot/index.d.ts | 39 ++++++++++++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/types/hubot/hubot-tests.ts b/types/hubot/hubot-tests.ts index 1c7540c950..c8df169659 100644 --- a/types/hubot/hubot-tests.ts +++ b/types/hubot/hubot-tests.ts @@ -1,9 +1,5 @@ import * as Hubot from "hubot"; -const brain = new Hubot.Brain(); -brain; // $ExpectType Brain -brain.userForName('someone'); // $ExpectType any - const robot = new Hubot.Robot<{}>( 'src/adapters', 'slack', @@ -13,3 +9,11 @@ const robot = new Hubot.Robot<{}>( robot; // $ExpectType Robot<{}> robot.adapter; // $ExpectType {} robot.hear(/hello/, () => null); // $ExpectType void +robot.on('test', () => null); // $ExpectType Robot<{}> +robot.emit('test', 'arg'); // $ExpectType boolean + +const brain = new Hubot.Brain(robot); +brain; // $ExpectType Brain<{}> +brain.userForName('someone'); // $ExpectType User +brain.get('test'); // $ExpectType any +brain.set('test', 'test'); // $ExpectType Brain<{}> diff --git a/types/hubot/index.d.ts b/types/hubot/index.d.ts index b0f465719a..40b5f74c5a 100644 --- a/types/hubot/index.d.ts +++ b/types/hubot/index.d.ts @@ -4,22 +4,43 @@ // Kees C. Bakker // Emil Marklund // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +/// + +import { EventEmitter } from 'events'; declare namespace Hubot { - class Brain { - userForId(id: any): any; - userForName(name: string): any; + class Brain extends EventEmitter { + constructor(robot: Robot); + set(key: string, value: any): this; + get(key: string): any; + remove(key: string): this; + save(): void; + close(): void; + setAutoSave(enabled: boolean): void; + resetSaveInterval(seconds: number): void; + mergeData(data: any): void; + users(): User[]; + userForId(id: any): User; + userForName(name: string): User; + userForRawFuzzyName(fuzzyName: string): User; + userForFuzzyName(fuzzyName: string): User; } class User { + constructor(id: any, options?: any); id: any; name: string; + [property: string]: any; } class Message { + constructor(user: User, done?: boolean) user: User; text: string; id: string; + finish(): void; } class Response { @@ -28,7 +49,11 @@ declare namespace Hubot { constructor(robot: R, message: Message, match: RegExpMatchArray); send(...strings: string[]): void; + emote(...strings: string[]): void; reply(...strings: string[]): void; + topic(...strings: string[]): void; + play(...strings: string[]): void; + locked(...strings: string[]): void; random(items: T[]): T; } @@ -36,7 +61,7 @@ declare namespace Hubot { class Robot { alias: string; - brain: Brain; + brain: Brain; name: string; readonly adapter: A; @@ -49,6 +74,12 @@ declare namespace Hubot { loadFile(directory: string, fileName: string): void; respond(regex: RegExp, callback: ListenerCallback): void; respond(regex: RegExp, options: any, callback: ListenerCallback): void; + enter(callback: ListenerCallback): void; + enter(options: any, callback: ListenerCallback): void; + topic(callback: ListenerCallback): void; + topic(options: any, callback: ListenerCallback): void; + on(event: string | symbol, listener: (...args: any[]) => void): this; + emit(event: string | symbol, ...args: any[]): boolean; } }