Course contentsShow
← TypeScript
Lesson 1554 of 1,79636. tRPC and End-to-End Type SafetyFree lesson

Type Inference Across the Wire

How TypeScript's type inference flows from server procedure definitions to client function calls.

Type Inference Across the Wire

What you'll learn: How TypeScript's type system automatically flows from your server's tRPC procedure definitions all the way to client function calls, creating end-to-end type safety without manual type declarations.

The Magic of Shared Type Information

In traditional REST APIs, you define types on the server, then separately define matching types on the client—maintaining two sources of truth that can drift apart. With tRPC, when you define a procedure on the server, TypeScript's inference engine automatically derives what types the client must use when calling that procedure.

Think of it like a telephone wire that carries not just the sound of your voice, but the actual meaning and grammar rules of your language. The server "speaks" with typed procedures, and the client "hears" those exact same types without anyone needing to translate.

How Inference Flows

When you create a tRPC procedure with an input schema and return type, TypeScript captures this information in the procedure's type signature. The tRPC client is generically typed to your entire router definition, so when you call a procedure from the client, TypeScript looks back at the server definition and infers:

  • What shape the input parameter must have
  • What type the returned Promise will resolve to
  • Whether the procedure is a query or mutation

No code generation, no manual type copying—just pure TypeScript inference working across your client and server boundary.

The End-to-End Connection

This "inference across the wire" means refactoring becomes safe: change your server's input schema or return type, and every client call site immediately shows a type error if it's now incorrect. Your types become a living contract that's always accurate because there's only one definition.

Key Takeaway: TypeScript's type inference flows from server procedure definitions to client function calls through generic type parameters, creating automatic end-to-end type safety without code generation or manual synchronization.