Skip to content

set thiscontext in action function #2197

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

Merged
merged 1 commit into from
May 30, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ export class Command {
*
* @returns `this` command for chaining
*/
action(fn: (...args: any[]) => void | Promise<void>): this;
action(fn: (this: this, ...args: any[]) => void | Promise<void>): this;

/**
* Define option with `flags`, `description`, and optional argument parsing function or `defaultValue` or both.
Expand Down
4 changes: 4 additions & 0 deletions typings/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ expectType<commander.Command>(
// action
expectType<commander.Command>(program.action(() => {}));
expectType<commander.Command>(program.action(async () => {}));
program
.action(function () {
expectType<typeof program>(this)
})

// option
expectType<commander.Command>(program.option('-a,--alpha'));
Expand Down