Skip to content

Commit

Permalink
Add more Option and Argument properties to typings (#2019)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowspawn committed Sep 21, 2023
1 parent 26a34e6 commit 744ee3f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions typings/index.d.ts
Expand Up @@ -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.
Expand Down Expand Up @@ -102,6 +105,8 @@ export class Option {
negate: boolean;
defaultValue?: any;
defaultValueDescription?: string;
presetArg?: unknown;
envVar?: string;
parseArg?: <T>(value: string, previous: T) => T;
hidden: boolean;
argChoices?: string[];
Expand Down
23 changes: 21 additions & 2 deletions typings/index.test-d.ts
Expand Up @@ -398,9 +398,25 @@ expectType<string>(helper.wrap('a b c', 50, 3));

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

// Option methods

// Option properties
const baseOption = new commander.Option('-f,--foo', 'foo description');
expectType<string>(baseOption.flags);
expectType<string>(baseOption.description);
expectType<boolean>(baseOption.required);
expectType<boolean>(baseOption.optional);
expectType<boolean>(baseOption.variadic);
expectType<boolean>(baseOption.mandatory);
expectType<string | undefined>(baseOption.short);
expectType<string | undefined>(baseOption.long);
expectType<boolean>(baseOption.negate);
expectType<any>(baseOption.defaultValue);
expectType<string | undefined>(baseOption.defaultValueDescription);
expectType<unknown>(baseOption.presetArg);
expectType<string | undefined>(baseOption.envVar);
expectType<boolean>(baseOption.hidden);
expectType<string[] | undefined>(baseOption.argChoices);

// Option methods

// default
expectType<commander.Option>(baseOption.default(3));
Expand Down Expand Up @@ -454,6 +470,9 @@ const baseArgument = new commander.Argument('<foo');
expectType<string>(baseArgument.description);
expectType<boolean>(baseArgument.required);
expectType<boolean>(baseArgument.variadic);
expectType<any>(baseArgument.defaultValue);
expectType<string | undefined>(baseArgument.defaultValueDescription);
expectType<string[] | undefined>(baseArgument.argChoices);

// Argument methods

Expand Down

0 comments on commit 744ee3f

Please sign in to comment.