Overview
The Hono client provides several utility types for extracting request and response types from your API endpoints, enabling full type safety in your client code.Import
Type Inference Utilities
InferRequestType
Extracts the request type (arguments) from a client endpoint method. Type Signature:InferResponseType
Extracts the response type from a client endpoint method, with optional status code filtering. Type Signature:endpoint method
required
The client endpoint method to infer from
number
default:"any status code"
Optional status code to filter by. Only returns the response type for matching status codes.
Client Configuration Types
ClientRequestOptions
Configuration options for the RPC client, used both at client creation and per-request. Type Definition:typeof fetch
Custom fetch implementation. Useful for testing with MSW or using node-fetch.
Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>)
Headers to include with requests. Can be static object or async function for dynamic headers.
RequestInit
Standard
RequestInit options. Takes highest priority and can override Hono’s automatic settings.BuildSearchParamsFn
Custom function to serialize query parameters.
(...args: ConstructorParameters<typeof WebSocket>) => WebSocket
Custom WebSocket constructor.
BuildSearchParamsFn
Function type for custom query parameter serialization. Type Definition:Response Types
ClientResponse
Type-safe response interface that extends the standardResponse with inferred types.
Type Definition:
generic
The response body type (inferred from server route)
number
The HTTP status code
ResponseFormat
The response format (‘json’, ‘text’, etc.)
- The
okproperty type is narrowed based on status code - The
json()method returnsPromise<T>with the inferred response type - The
text()method returnsPromise<string>(orPromise<T>for text responses)
FilterClientResponseByStatusCode
Filters aClientResponse type to only include specific status codes.
Type Definition: