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: export constituent types of TypedCommandParameters individually #24

Merged
merged 2 commits into from
Oct 22, 2024
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
8 changes: 7 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ export {
UnsatisfiedPositionalError,
formatMessageForArgumentScannerError,
} from "./parameter/scanner";
export type { InputParser, TypedCommandParameters } from "./parameter/types";
export type {
Aliases,
InputParser,
TypedCommandFlagParameters,
TypedCommandParameters,
TypedCommandPositionalParameters,
} from "./parameter/types";
export { buildCommand } from "./routing/command/builder";
export type { CommandBuilderArguments } from "./routing/command/builder";
export type { Command } from "./routing/command/types";
Expand Down
18 changes: 9 additions & 9 deletions packages/core/src/parameter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export type Aliases<T> = Readonly<Partial<Record<AvailableAlias, T>>>;

export type BaseFlags = Readonly<Record<string, unknown>>;

interface TypedCommandFlagParameters<FLAGS extends BaseFlags, CONTEXT extends CommandContext> {
interface TypedCommandFlagParameters_<FLAGS extends BaseFlags, CONTEXT extends CommandContext> {
/**
* Typed definitions for all flag parameters.
*/
Expand All @@ -72,21 +72,21 @@ interface TypedCommandFlagParameters<FLAGS extends BaseFlags, CONTEXT extends Co
readonly aliases?: Aliases<keyof FLAGS & string>;
}

type TypedCommandFlagParameters_<FLAGS extends BaseFlags, CONTEXT extends CommandContext> =
export type TypedCommandFlagParameters<FLAGS extends BaseFlags, CONTEXT extends CommandContext> =
Record<string, never> extends FLAGS
? Partial<TypedCommandFlagParameters<FLAGS, CONTEXT>>
: TypedCommandFlagParameters<FLAGS, CONTEXT>;
? Partial<TypedCommandFlagParameters_<FLAGS, CONTEXT>>
: TypedCommandFlagParameters_<FLAGS, CONTEXT>;

interface TypedCommandPositionalParameters<ARGS extends BaseArgs, CONTEXT extends CommandContext> {
interface TypedCommandPositionalParameters_<ARGS extends BaseArgs, CONTEXT extends CommandContext> {
/**
* Typed definitions for all positional parameters.
*/
readonly positional: TypedPositionalParameters<ARGS, CONTEXT>;
}

type TypedCommandPositionalParameters_<ARGS extends BaseArgs, CONTEXT extends CommandContext> = [] extends ARGS
? Partial<TypedCommandPositionalParameters<ARGS, CONTEXT>>
: TypedCommandPositionalParameters<ARGS, CONTEXT>;
export type TypedCommandPositionalParameters<ARGS extends BaseArgs, CONTEXT extends CommandContext> = [] extends ARGS
? Partial<TypedCommandPositionalParameters_<ARGS, CONTEXT>>
: TypedCommandPositionalParameters_<ARGS, CONTEXT>;

/**
* Definitions for all parameters requested by the corresponding command.
Expand All @@ -95,7 +95,7 @@ export type TypedCommandParameters<
FLAGS extends BaseFlags,
ARGS extends BaseArgs,
CONTEXT extends CommandContext,
> = TypedCommandFlagParameters_<FLAGS, CONTEXT> & TypedCommandPositionalParameters_<ARGS, CONTEXT>;
> = TypedCommandFlagParameters<FLAGS, CONTEXT> & TypedCommandPositionalParameters<ARGS, CONTEXT>;

/**
* Definitions for all parameters requested by the corresponding command.
Expand Down