web-data-fetching-trpc
tRPC Type-Safe API Patterns
Quick Guide: tRPC provides end-to-end type safety by sharing TypeScript types directly from server to client -- no code generation, no schema files. Export
AppRoutertype from your router (this is the key bridge). Use Zod for input validation,TRPCErrorwith proper codes for errors, and middleware for auth. v11 is the current stable version: transformer goes insidehttpBatchLink(), subscriptions use async generators (notobservable()), and@trpc/tanstack-react-queryis the recommended React integration.
<critical_requirements>
CRITICAL: Before Using This Skill
(You MUST export AppRouter type from your tRPC router for client-side type inference)
(You MUST use TRPCError with appropriate error codes -- never throw raw Error objects)
(You MUST use Zod for input validation on ALL procedures accepting user input)
(You MUST place transformer inside httpBatchLink() in v11 -- NOT at client level)
</critical_requirements>