From 8b5599e696b6d3e9b59b2d88c968a48908a3273c Mon Sep 17 00:00:00 2001 From: John Gee Date: Mon, 10 May 2021 11:00:28 +1200 Subject: [PATCH] Simplify addHelpText TypeScript signature and improve typings test (#1516) --- typings/index.d.ts | 2 +- typings/index.test-d.ts | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 64e08d00d..668790ba8 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -640,7 +640,7 @@ declare namespace commander { * and 'beforeAll' or 'afterAll' to affect this command and all its subcommands. */ addHelpText(position: AddHelpTextPosition, text: string): this; - addHelpText(position: AddHelpTextPosition, text: (context: AddHelpTextContext) => string | undefined): this; + addHelpText(position: AddHelpTextPosition, text: (context: AddHelpTextContext) => string): this; /** * Add a listener (callback) for when events occur. (Implemented using EventEmitter.) diff --git a/typings/index.test-d.ts b/typings/index.test-d.ts index 0f5495952..f23dba79b 100644 --- a/typings/index.test-d.ts +++ b/typings/index.test-d.ts @@ -224,11 +224,10 @@ expectType(program.helpOption(false)); expectType(program.addHelpText('after', 'text')); expectType(program.addHelpText('afterAll', 'text')); expectType(program.addHelpText('before', () => 'before')); -expectType(program.addHelpText('beforeAll', (context: commander.AddHelpTextContext) => { - if (context.error) { - return; // Can return nothing to skip display - } - return context.command.name(); +expectType(program.addHelpText('beforeAll', (context) => { + expectType(context.error); + expectType(context.command); + return ''; })); // on