diff --git a/index.d.ts b/index.d.ts index ee39351..4ae9a9e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -691,7 +691,7 @@ export class CommanderError extends Error { * * @returns `this` command for chaining */ - action(fn: (...args: [...Args, Opts, this]) => void | Promise): this; + action(fn: (this: this, ...args: [...Args, Opts, this]) => void | Promise): this; /** * Define option with `flags`, `description`, and optional argument parsing function or `defaultValue` or both. diff --git a/tests/arguments.test-d.ts b/tests/arguments.test-d.ts index 76d7aed..c9bdf12 100644 --- a/tests/arguments.test-d.ts +++ b/tests/arguments.test-d.ts @@ -314,6 +314,16 @@ program expectAssignable(options); }); +// `this` should be current Command +program + .option('-o, --opt') + .option('-v, --verbose') + .argument('') + .argument('') + .action(function () { + expectType>(this) + }) + // default type ignored when arg is required expectType<('C')>( program