Kind: Type
Source: src/validator/utils.ts
Utility type to infer input types for validation targets. Preserves literal union types (e.g., 'asc' | 'desc') while using the default ValidationTargets type for other values.
InferInput derives the input type accepted by a validation target. It preserves literal unions such as 'asc' | 'desc' and falls back to ValidationTargets for other target values.
Definition
ts[Exclude<Output, undefined>] extends [never] ? {} : [Exclude<Output, undefined>] extends [object] ? undefined extends Output ? SimplifyDeep<InferInputInner<Exclude<Output, undefined>, Target, T>> | undefined : SimplifyDeep<InferInputInner<Output, Target, T>> : {}
Diagram
mermaidgraph LR A[Validation target type] --> B[InferInput] B --> C[Literal union preserved] B --> D[Other values use ValidationTargets]
Usage
tsimport type { InferInput } from './validator/utils';
type SortDirection = InferInput<'asc' | 'desc'>;
const direction: SortDirection = 'asc';
// const invalidDirection: SortDirection = 'up'; // Type error
AI Coding Instructions
- Keep literal union types intact when passing them through
InferInput. - Use
InferInputfor validator-facing input types rather than widening values tostring. - Treat
ValidationTargetsas the fallback type for inputs that are not preserved literal unions. - Update related validator type definitions if supported validation target shapes change.
Was this page helpful?