tRPC Procedure Basics
You'll learn: How tRPC procedures work and how TypeScript types flow automatically from server to client without manual type definitions.
What is a tRPC Procedure?
A procedure in tRPC is a backend function that can be called from the frontend. Think of it like an API endpoint, but instead of manually defining types on both sides, TypeScript inference handles everything.
The magic happens because tRPC routers group procedures together, and TypeScript traces the exact shape of your server functions all the way to your client code. When you define a procedure's input and output on the server, your client automatically "knows" these types without importing them or writing duplicate interfaces.
How Type Inference Flows
- Server side: You define a procedure with input validation (using Zod or similar) and return a typed value
- tRPC creates the router: Your procedures are grouped into a router object
- Client imports the router type: Not the implementation, just the type signature
- Full autocomplete: Your editor knows exactly what data to send and what you'll receive back
This is different from REST or GraphQL where you either write types twice or generate them with code-gen tools. With tRPC, you define types once on the server, and TypeScript's inference propagates them to every client call site.
Why This Matters
No more drift between frontend and backend types. If you change a procedure's return type on the server, every client calling it immediately shows a type error. You get end-to-end type safety with zero runtime overhead and zero manual type duplication.
Key Takeaway: tRPC procedures let you define backend functions once, and TypeScript automatically provides full type safety on the frontend through router type inference, eliminating manual type duplication.