Skip to content

Missing this type for action #2145

@matthyk

Description

@matthyk

commander.js/lib/command.js

Lines 511 to 527 in 83c3f4e

action(fn) {
const listener = (args) => {
// The .action callback takes an extra parameter which is the command or options.
const expectedArgsCount = this.registeredArguments.length;
const actionArgs = args.slice(0, expectedArgsCount);
if (this._storeOptionsAsProperties) {
actionArgs[expectedArgsCount] = this; // backwards compatible "options"
} else {
actionArgs[expectedArgsCount] = this.opts();
}
actionArgs.push(this);
return fn.apply(this, actionArgs);
};
this._actionHandler = listener;
return this;
}

The passed action function fn receives the current command as this context in line 523. However, this context is missing in the current typings.
action(fn: (...args: any[]) => void | Promise<void>): this;

Happy to provide a PR for this!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions