From 72062a5981d5236f0d71da73c102c6a556b4e2c8 Mon Sep 17 00:00:00 2001 From: Prokop Simek Date: Wed, 29 Jan 2020 16:58:53 +0100 Subject: [PATCH] fix(ts): action can be an async function Since we can use `parseAsync` for async functions so the action can be asynchronous. related to https://github.com/tj/commander.js/issues/806 --- typings/commander-tests.ts | 10 ++++++++++ typings/index.d.ts | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/typings/commander-tests.ts b/typings/commander-tests.ts index 7661bcf0e..1bc0f48a3 100644 --- a/typings/commander-tests.ts +++ b/typings/commander-tests.ts @@ -45,6 +45,14 @@ function increaseVerbosity(v: any, total: number) { return total + 1; } +function syncCall() { + console.log("Sync success!"); +} + +async function asyncCall() { + return; +} + program .version('0.0.1') .usage('[options] ') @@ -112,6 +120,8 @@ program program .command("name1", "description") .command("name2", "description", { isDefault:true }) + .command("name3", "description").action(syncCall) + .command("name4", "description").action(asyncCall) program .exitOverride(); diff --git a/typings/index.d.ts b/typings/index.d.ts index d1a89d8c2..082a3a3c2 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -115,7 +115,7 @@ declare namespace commander { * * @returns Command for chaining */ - action(fn: (...args: any[]) => void): Command; + action(fn: (...args: any[]) => void | Promise): Command; /** * Define option with `flags`, `description` and optional