Skip to content

Commit 744ee3f

Browse files
authored
Add more Option and Argument properties to typings (#2019)
1 parent 26a34e6 commit 744ee3f

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

typings/index.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ export class Argument {
5050
description: string;
5151
required: boolean;
5252
variadic: boolean;
53+
defaultValue?: any;
54+
defaultValueDescription?: string;
55+
argChoices?: string[];
5356

5457
/**
5558
* Initialize a new command argument with the given name and description.
@@ -102,6 +105,8 @@ export class Option {
102105
negate: boolean;
103106
defaultValue?: any;
104107
defaultValueDescription?: string;
108+
presetArg?: unknown;
109+
envVar?: string;
105110
parseArg?: <T>(value: string, previous: T) => T;
106111
hidden: boolean;
107112
argChoices?: string[];

typings/index.test-d.ts

+21-2
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,25 @@ expectType<string>(helper.wrap('a b c', 50, 3));
398398

399399
expectType<string>(helper.formatHelp(helperCommand, helper));
400400

401-
// Option methods
402-
401+
// Option properties
403402
const baseOption = new commander.Option('-f,--foo', 'foo description');
403+
expectType<string>(baseOption.flags);
404+
expectType<string>(baseOption.description);
405+
expectType<boolean>(baseOption.required);
406+
expectType<boolean>(baseOption.optional);
407+
expectType<boolean>(baseOption.variadic);
408+
expectType<boolean>(baseOption.mandatory);
409+
expectType<string | undefined>(baseOption.short);
410+
expectType<string | undefined>(baseOption.long);
411+
expectType<boolean>(baseOption.negate);
412+
expectType<any>(baseOption.defaultValue);
413+
expectType<string | undefined>(baseOption.defaultValueDescription);
414+
expectType<unknown>(baseOption.presetArg);
415+
expectType<string | undefined>(baseOption.envVar);
416+
expectType<boolean>(baseOption.hidden);
417+
expectType<string[] | undefined>(baseOption.argChoices);
418+
419+
// Option methods
404420

405421
// default
406422
expectType<commander.Option>(baseOption.default(3));
@@ -454,6 +470,9 @@ const baseArgument = new commander.Argument('<foo');
454470
expectType<string>(baseArgument.description);
455471
expectType<boolean>(baseArgument.required);
456472
expectType<boolean>(baseArgument.variadic);
473+
expectType<any>(baseArgument.defaultValue);
474+
expectType<string | undefined>(baseArgument.defaultValueDescription);
475+
expectType<string[] | undefined>(baseArgument.argChoices);
457476

458477
// Argument methods
459478

0 commit comments

Comments
 (0)