Skip to content

Commit

Permalink
Simplify addHelpText TypeScript signature and improve typings test (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowspawn committed May 9, 2021
1 parent 59c8153 commit 8b5599e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion typings/index.d.ts
Expand Up @@ -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.)
Expand Down
9 changes: 4 additions & 5 deletions typings/index.test-d.ts
Expand Up @@ -224,11 +224,10 @@ expectType<commander.Command>(program.helpOption(false));
expectType<commander.Command>(program.addHelpText('after', 'text'));
expectType<commander.Command>(program.addHelpText('afterAll', 'text'));
expectType<commander.Command>(program.addHelpText('before', () => 'before'));
expectType<commander.Command>(program.addHelpText('beforeAll', (context: commander.AddHelpTextContext) => {
if (context.error) {
return; // Can return nothing to skip display
}
return context.command.name();
expectType<commander.Command>(program.addHelpText('beforeAll', (context) => {
expectType<boolean>(context.error);
expectType<commander.Command>(context.command);
return '';
}));

// on
Expand Down

0 comments on commit 8b5599e

Please sign in to comment.