Skip to main content

End-to-End Type Safety

One of Hono’s most powerful features is its end-to-end type safety. The RPC client uses TypeScript’s type inference to automatically derive types from your server routes - no code generation or manual type definitions needed.

Type Inference

TypeScript automatically infers types from your Hono app definition. This includes:
  • Route paths and parameters
  • Request body types (JSON, form data)
  • Query parameters
  • Response body types
  • HTTP status codes
The type inference works entirely at compile time - there’s no runtime overhead.

InferResponseType

The InferResponseType utility type extracts the response type from a client method:

Usage in Components

This is especially useful when passing data to components:

InferRequestType

The InferRequestType utility type extracts the request parameter types:

Status Code Types

When your server returns different types based on status codes, the client preserves this information:

InferResponseType with Status Codes

You can specify a status code to narrow the response type:

Validation Types

When using validators on the server, the client automatically knows about required parameters:

Request Body Types

JSON Bodies

Form Data

Optional and Required Parameters

The client automatically distinguishes between required and optional parameters:

Type-safe Response Methods

The client response object has typed methods based on the content type:

Complex Type Scenarios

Union Types

Nested Routes

Best Practices

Always export the app type so clients can import it:
Extract response types for use in multiple places:
Use status codes to narrow response types:
The types are derived from your server code. When you change routes, the client types update automatically.

What’s Next?

Usage Guide

Learn practical patterns for using the client

Validators

Add runtime validation to your routes