import { FnInput } from "../reducer/lambda/FnInput.js"; import { FrType } from "./FrType.js"; type Props = { name?: string; type: FrType; }; export class FrInput { readonly name: string | undefined; readonly optional: IsOptional; readonly type: FrType; constructor(props: Props, optional: IsOptional) { this.name = props.name; this.type = props.type; this.optional = optional; } toFnInput() { return new FnInput({ name: this.name, optional: this.optional, type: this.type.type, }); } toString() { return this.toFnInput().toString(); } } // `frInput` and `frOptionalInput` are separate, because we really care about type inference based on the optional flag. export function frInput(props: Props) { return new FrInput(props, false); } // If `frOptionalInput` is used, the function definition's parameter will be inferred to `T | null`. export function frOptionalInput(props: Props) { return new FrInput(props, true); } // shortcut for named input export function namedInput(name: string, type: FrType) { return new FrInput( { type, name, }, false ); }