Menu

Post image 1
Post image 2
Post image 3
Post image 4
Post image 5
1 / 5
0

Building a tRPC Router from First Principles

DEV Community·Gabriel Anhaia·30 days ago
#54rofJ8I
Reading 0:00
15s threshold

Book: TypeScript in Production — Tooling, Build, and Library Authoring Across Runtimes Also by me: The TypeScript Library — the 5-book collection My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools Me: xgabriel.com | GitHub You add a greet route on the server that takes { name: string } and returns a string. After saving, you flip to the client tab and start typing client.greet.query({ , and autocomplete already shows name . Type a wrong value, the squiggle fires before you finish. Nothing was generated, no OpenAPI document was rebuilt, no watcher kicked in. The server route is plain TypeScript, the client is plain TypeScript, they talk over JSON. How does tRPC do that? The answer is two type-system tricks and a transport. Once you see them, both tricks look small. Small enough that ~200 lines of TypeScript gets you the same end-to-end type safety in your own codebase, without the dependency or the migration guide every two years.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More