Skip to content

Commit

Permalink
fix: type untyped args as string | boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Mar 31, 2023
1 parent 47398f1 commit 4c9582f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export function parseArgs(rawArgs: string[], argsDef: ArgsDef): ParsedArgs {
const parseOptions = {
boolean: [] as string[],
string: [] as string[],
mixed: [] as string[],
alias: {} as Record<string, string | string[]>,
default: {} as Record<string, boolean | string>,
};
Expand All @@ -17,7 +18,11 @@ export function parseArgs(rawArgs: string[], argsDef: ArgsDef): ParsedArgs {
if (arg.type === "positional") {
continue;
}
parseOptions[arg.type || "boolean"].push(arg.name);
if (arg.type === "string") {
parseOptions.string.push(arg.name);
} else if (arg.type === "boolean") {
parseOptions.boolean.push(arg.name);
}
if (arg.default !== undefined) {
parseOptions.default[arg.name] = arg.default;
}
Expand Down
8 changes: 7 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type Arg = ArgDef & { name: string; alias: string[] };

export type ParsedArgs<T extends ArgsDef = ArgsDef> = { _: string[] } & Record<
{ [K in keyof T]: T[K] extends { type: "positional" } ? K : never }[keyof T],
string | boolean
string
> &
Record<
{
Expand All @@ -33,6 +33,12 @@ export type ParsedArgs<T extends ArgsDef = ArgsDef> = { _: string[] } & Record<
[K in keyof T]: T[K] extends { type: "boolean" } ? K : never;
}[keyof T],
boolean
> &
Record<
{
[K in keyof T]: T[K] extends {} ? K : never;
}[keyof T],
string | boolean
>;

// ----- Command -----
Expand Down

0 comments on commit 4c9582f

Please sign in to comment.