Skip to content
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
15 changes: 8 additions & 7 deletions lib/param.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
type Unary,
} from "./pipeline.ts";
import type { CLIBinding } from "./read.ts";
import type { Definition, Schema } from "./types.ts";
import type { Definition, OutputOf, Schema } from "./types.ts";

export interface Param<K extends string, T> extends Definition<K> {
schema: Schema<T>;
Expand Down Expand Up @@ -49,18 +49,19 @@ export function param<
) as Fold<Param<K, unknown>, E>;
}

export function schema<T>(
schema: Schema<T>,
): TransformElement<SchemaTransform<T>> {
return mark<SchemaTransform<T>>((param: Param<string, unknown>) => ({
export function schema<S extends Schema>(
schema: S,
): TransformElement<SchemaTransform<S>> {
return mark<SchemaTransform<S>>((param: Param<string, unknown>) => ({
...param,
schema,
}));
}

interface SchemaTransform<T> extends Transform {
interface SchemaTransform<S extends Schema> extends Transform {
readonly input: Param<string, unknown>;
readonly output: this["input"] extends Param<infer N, unknown> ? Param<N, T>
readonly output: this["input"] extends Param<infer N, unknown>
? Param<N, OutputOf<S>>
: never;
}

Expand Down
6 changes: 5 additions & 1 deletion lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import type { Result } from "./result.ts";
import type { ValueSource } from "./values.ts";

export type Issue = StandardSchemaV1.Issue;
export type Schema<T> = StandardSchemaV1<T, T>;
export type Schema<Input = unknown, Output = Input> = StandardSchemaV1<
Input,
Output
>;
export type OutputOf<S extends Schema> = StandardSchemaV1.InferOutput<S>;

export interface Definition<N extends string> {
readonly name: N;
Expand Down
Loading