From c448afba945943097ae323959d73a049efad3485 Mon Sep 17 00:00:00 2001 From: John Gee Date: Sun, 12 Jan 2020 07:02:15 +1300 Subject: [PATCH] Remove EventEmitter from TypeScript definition file (#1146) * Remove NodeJS.EventEmitter from TypeScript definition * Add symbol It is JavaScript not node and ok to include to match EventEmitter defintition --- Readme.md | 7 +------ typings/index.d.ts | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Readme.md b/Readme.md index aa4f42b59..14e11c975 100644 --- a/Readme.md +++ b/Readme.md @@ -605,12 +605,7 @@ console.log(programOptions.name); ### TypeScript -The Commander package includes its TypeScript Definition file, but also requires the node types which you need to install yourself. e.g. - -```bash -npm install commander -npm install --save-dev @types/node -``` +The Commander package includes its TypeScript Definition file. If you use `ts-node` and git-style sub-commands written as `.ts` files, you need to call your program through node to get the sub-commands called correctly. e.g. diff --git a/typings/index.d.ts b/typings/index.d.ts index 0a53fdf79..4078b795d 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1,8 +1,6 @@ // Type definitions for commander // Original definitions by: Alan Agius , Marcelo Dezem , vvakame , Jules Randolph -/// - declare namespace commander { interface CommanderError extends Error { @@ -25,7 +23,7 @@ declare namespace commander { } type OptionConstructor = { new (flags: string, description?: string): Option }; - interface Command extends NodeJS.EventEmitter { + interface Command { [key: string]: any; // options as properties args: string[]; @@ -286,6 +284,17 @@ declare namespace commander { * Output help information and exit. */ help(cb?: (str: string) => string): never; + + /** + * Add a listener (callback) for when events occur. (Implemented using EventEmitter.) + * + * @example + * program + * .on('--help', () -> { + * console.log('See web site for more information.'); + * }); + */ + on(event: string | symbol, listener: (...args: any[]) => void): Command; } type CommandConstructor = { new (name?: string): Command };