Client-Server Type Inference
Get fully typed clients without code generation.
Sharing the Router Type
The client gains type safety by importing the server router type. This is a type-only import: nothing from the server runs in the client; only the static contract crosses the boundary.
import type { AppRouter } from '../server/router';
// type-only import - erased at build timeCreating a Typed Client
Use createTRPCClient (or the proxy variant) parameterized by AppRouter. The client object then mirrors the server router shape, with full autocomplete for every procedure.
import { createTRPCClient, httpBatchLink } from '@trpc/client';
const client = createTRPCClient<AppRouter>({
links: [httpBatchLink({ url: 'http://localhost:3000' })],
});All lessons in this course
- The tRPC Architecture
- Defining Routers and Procedures
- Client-Server Type Inference
- Middleware and Context