Skip to content

Commit cb54d5f

Browse files
authored
fix(ts): action can be an async function (#1157)
Since we can use `parseAsync` for async functions so the action can be asynchronous. related to #806
1 parent 6791884 commit cb54d5f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

typings/commander-tests.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ function increaseVerbosity(v: any, total: number) {
4545
return total + 1;
4646
}
4747

48+
function syncCall() {
49+
console.log("Sync success!");
50+
}
51+
52+
async function asyncCall() {
53+
return;
54+
}
55+
4856
program
4957
.version('0.0.1')
5058
.usage('[options] <file ...>')
@@ -111,7 +119,11 @@ program
111119

112120
program
113121
.command("name1", "description")
114-
.command("name2", "description", { isDefault:true })
122+
.command("name2", "description", { isDefault:true });
123+
124+
program
125+
.command("name3").action(syncCall)
126+
.command("name4").action(asyncCall);
115127

116128
program
117129
.exitOverride();

typings/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ declare namespace commander {
115115
*
116116
* @returns Command for chaining
117117
*/
118-
action(fn: (...args: any[]) => void): Command;
118+
action(fn: (...args: any[]) => void | Promise<void>): Command;
119119

120120
/**
121121
* Define option with `flags`, `description` and optional

0 commit comments

Comments
 (0)