Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(command): infer option default value as const #660

Merged
merged 3 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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