From 94a9a35db8493f497b929bf02d1598f7ad2f40e1 Mon Sep 17 00:00:00 2001 From: Prokop Simek Date: Sun, 2 Feb 2020 02:13:24 +0100 Subject: [PATCH] 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 https://github.com/tj/commander.js/issues/806 --- typings/commander-tests.ts | 14 +++++++++++++- typings/index.d.ts | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/typings/commander-tests.ts b/typings/commander-tests.ts index 7661bcf..1c209d0 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] ') @@ -111,7 +119,11 @@ program program .command("name1", "description") - .command("name2", "description", { isDefault:true }) + .command("name2", "description", { isDefault:true }); + +program + .command("name3").action(syncCall) + .command("name4").action(asyncCall); program .exitOverride(); diff --git a/typings/index.d.ts b/typings/index.d.ts index d1a89d8..082a3a3 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