# InferInput

**Kind:** Type

**Source:** [`src/validator/utils.ts`](https://github.com/honojs/hono/blob/main/src/validator/utils.ts#L59)

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

```mermaid
graph LR
  A[Validation target type] --> B[InferInput]
  B --> C[Literal union preserved]
  B --> D[Other values use ValidationTargets]
```

## Usage

```ts
import 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 `InferInput` for validator-facing input types rather than widening values to `string`.
- Treat `ValidationTargets` as the fallback type for inputs that are not preserved literal unions.
- Update related validator type definitions if supported validation target shapes change.
