Skip to content

Commit 22239e6

Browse files
authored
set thiscontext (#2197)
1 parent 8641554 commit 22239e6

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

typings/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ export class Command {
544544
*
545545
* @returns `this` command for chaining
546546
*/
547-
action(fn: (...args: any[]) => void | Promise<void>): this;
547+
action(fn: (this: this, ...args: any[]) => void | Promise<void>): this;
548548

549549
/**
550550
* Define option with `flags`, `description`, and optional argument parsing function or `defaultValue` or both.

typings/index.test-d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ expectType<commander.Command>(
148148
// action
149149
expectType<commander.Command>(program.action(() => {}));
150150
expectType<commander.Command>(program.action(async () => {}));
151+
program
152+
.action(function () {
153+
expectType<typeof program>(this)
154+
})
151155

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

0 commit comments

Comments
 (0)