0Pricing
TypeScript Academy · Lesson

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 time

Creating 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

  1. The tRPC Architecture
  2. Defining Routers and Procedures
  3. Client-Server Type Inference
  4. Middleware and Context
← Back to TypeScript Academy