Skip to content

Commit

Permalink
fix(command): infer option default value as const (#660)
Browse files Browse the repository at this point in the history
  • Loading branch information
c4spar authored Sep 13, 2023
1 parent 5118a1c commit c91ddb6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions command/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ export class Command<
TRequired extends OptionOptions["required"] = undefined,
TCollect extends OptionOptions["collect"] = undefined,
TConflicts extends OptionOptions["conflicts"] = undefined,
TDefaultValue = undefined,
const TDefaultValue = undefined,
TMappedValue = undefined,
>(
flags: TFlags,
Expand Down Expand Up @@ -1304,7 +1304,7 @@ export class Command<
TCommandOptions,
Merge<TParentCommandTypes, Merge<TCommandGlobalTypes, TCommandTypes>>,
undefined extends TConflicts ? TRequired : false,
TDefault
TDefaultValue
>,
TMappedGlobalOptions extends MapValue<
TGlobalOptions,
Expand All @@ -1314,7 +1314,7 @@ export class Command<
TRequired extends OptionOptions["required"] = undefined,
TCollect extends OptionOptions["collect"] = undefined,
TConflicts extends OptionOptions["conflicts"] = undefined,
TDefault = undefined,
const TDefaultValue = undefined,
TMappedValue = undefined,
>(
flags: TFlags,
Expand All @@ -1335,7 +1335,7 @@ export class Command<
>
& {
global: true;
default?: DefaultValue<TDefault>;
default?: DefaultValue<TDefaultValue>;
required?: TRequired;
collect?: TCollect;
value?: OptionValueHandler<
Expand Down Expand Up @@ -1375,7 +1375,7 @@ export class Command<
TRequired extends OptionOptions["required"] = undefined,
TCollect extends OptionOptions["collect"] = undefined,
TConflicts extends OptionOptions["conflicts"] = undefined,
TDefaultValue = undefined,
const TDefaultValue = undefined,
TMappedValue = undefined,
>(
flags: TFlags,
Expand Down
14 changes: 7 additions & 7 deletions command/test/command/generic_types_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ import {
.type("color", colorType)
.option("--foo [val:string]", "...")
.option("--bar [val:string]", "...", { default: 4 })
.option("--baz <val:color>", "...", { default: "red" as const })
.option("--baz <val:color>", "...", { default: "red" })
.option("--beep <val:string> [val:string]", "...", {
default: new Date(),
global: true,
Expand All @@ -771,11 +771,11 @@ import {
assert<
IsExact<typeof options, {
foo?: string | true;
bar: string | number | true;
bar: string | true | 4;
baz: "red" | "blue";
beep: Date | [string, string?];
boop: Date | [string, number?];
one: { two: string | number };
one: { two: string | 4 };
}>
>(true);
});
Expand Down Expand Up @@ -809,7 +809,7 @@ import {
.option("--one.foo <val:string>", "...", {
default: 4,
value: (value) => {
assert<IsExact<typeof value, number | string>>(true);
assert<IsExact<typeof value, string | 4>>(true);
return new Date();
},
})
Expand Down Expand Up @@ -849,8 +849,8 @@ import {
beep: Map<string, number>;
boop: Array<Date>;
foo?: string | true;
bar: string | number | true;
baz: string | number;
bar: string | true | 4;
baz: string | 4;
one: { foo: Date; bar?: RegExp };
three?: { four?: number };
envVar: Date;
Expand Down Expand Up @@ -944,7 +944,7 @@ import {
color: string | false;
check: boolean;
remote?: string | false;
defaultValue: number | false;
defaultValue: false | 5;
}>
>(true);
});
Expand Down

0 comments on commit c91ddb6

Please sign in to comment.