tRPC lets a TypeScript server expose a router of queries and mutations that a client can call as ordinary functions. The types of inputs and outputs flow from the server definition straight into the client through TypeScript inference, so renaming a field or changing a return shape produces a compile error in the calling code instead of a runtime surprise. There is no build step that generates client code and no separate schema language to keep in sync.
Procedures are organised into nested routers, with input validation commonly delegated to a schema library, middleware for authentication and logging, and both query and mutation primitives. Adapters exist for popular Node servers, serverless functions and modern full-stack frameworks, while client integrations cover React, Next.js and plain TypeScript. Batching, request cancellation, error formatting and context creation are provided by small composable links rather than a heavy runtime.
It suits small to medium TypeScript teams that own both ends of an application, internal tools and dashboards that need to move quickly, and monorepos where frontend and backend already share types. Because the contract is the code itself, adding a field to a response becomes a single edit, and editors can autocomplete procedure names and argument shapes across the repository without extra tooling.
Compared with REST plus hand-written clients, tRPC removes duplicated DTOs and the risk of stale documentation. Compared with GraphQL, it is far lighter and requires no query language or resolver schema, but it does not offer flexible client-driven field selection. Compared with code-generation approaches, iteration is faster, though the approach assumes both sides are TypeScript and live in the same type-checkable project, which limits its use for public APIs consumed by other languages.
Because procedures are inferred rather than described by an external contract, breaking changes surface at compile time only when client and server are type-checked together; publishing a separately versioned client requires more care. Input validation should never be skipped, since TypeScript types disappear at runtime. Teams should also review caching and batching behaviour against their deployment platform before enabling it broadly.
407106872@qq.com
Copyright © 2026 Torv.cn All Rights Reserved.