Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify addHelpText TypeScript signature and improve typings test #1516

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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