From 744ee3f307dd9581a0b11906eea134b22dd1369a Mon Sep 17 00:00:00 2001 From: John Gee Date: Thu, 21 Sep 2023 18:57:34 +1200 Subject: [PATCH] Add more Option and Argument properties to typings (#2019) --- typings/index.d.ts | 5 +++++ typings/index.test-d.ts | 23 +++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 8d1aead56..e77cb1bf3 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -50,6 +50,9 @@ export class Argument { description: string; required: boolean; variadic: boolean; + defaultValue?: any; + defaultValueDescription?: string; + argChoices?: string[]; /** * Initialize a new command argument with the given name and description. @@ -102,6 +105,8 @@ export class Option { negate: boolean; defaultValue?: any; defaultValueDescription?: string; + presetArg?: unknown; + envVar?: string; parseArg?: (value: string, previous: T) => T; hidden: boolean; argChoices?: string[]; diff --git a/typings/index.test-d.ts b/typings/index.test-d.ts index c8db518bb..22706982b 100644 --- a/typings/index.test-d.ts +++ b/typings/index.test-d.ts @@ -398,9 +398,25 @@ expectType(helper.wrap('a b c', 50, 3)); expectType(helper.formatHelp(helperCommand, helper)); -// Option methods - +// Option properties const baseOption = new commander.Option('-f,--foo', 'foo description'); +expectType(baseOption.flags); +expectType(baseOption.description); +expectType(baseOption.required); +expectType(baseOption.optional); +expectType(baseOption.variadic); +expectType(baseOption.mandatory); +expectType(baseOption.short); +expectType(baseOption.long); +expectType(baseOption.negate); +expectType(baseOption.defaultValue); +expectType(baseOption.defaultValueDescription); +expectType(baseOption.presetArg); +expectType(baseOption.envVar); +expectType(baseOption.hidden); +expectType(baseOption.argChoices); + +// Option methods // default expectType(baseOption.default(3)); @@ -454,6 +470,9 @@ const baseArgument = new commander.Argument('(baseArgument.description); expectType(baseArgument.required); expectType(baseArgument.variadic); +expectType(baseArgument.defaultValue); +expectType(baseArgument.defaultValueDescription); +expectType(baseArgument.argChoices); // Argument methods