TypeScript with tRPC: End-to-End Type Safety for Full-Stack Development

Why do so many developers still rely on REST APIs when full-stack TypeScript with tRPC offers end-to-end type safety out of the box? I recently used vibe coding to prototype a small app, and the seamless type-sharing between server and client blew me away. No duplicated types, no runtime type errors, just pure TypeScript confidence throughout the stack. Here’s how simple it can be: ```typescript // server/router.ts import { initTRPC } from '@trpc/server' const t = initTRPC.create() export const appRouter = t.router({ greet: t.procedure .input(({ name }: { name: string }) => name) .query(({ input }) => `Hello, ${input}!`), }) export type AppRouter = typeof appRouter // client.ts import { createTRPCProxyClient, httpBatchLink } from '@trpc/client' import type { AppRouter } from './server/router' const client = createTRPCProxyClient<AppRouter>({ links: [httpBatchLink({ url: '/trpc' })], }) async function sayHello() { const greeting = await client.greet.query('TypeScript') console.log(greeting) // "Hello, TypeScript!" } sayHello() ``` No need to write OpenAPI specs or generate client SDKs. When I tweak my backend types, the client instantly picks up the change, reducing integration bugs drastically. This workflow has saved me hours and prevented those frustrating “but it worked yesterday” moments. Has anyone else embraced full-stack TypeScript with tRPC? What challenges did you face moving away from REST or GraphQL? #WebDevelopment #TypeScript #Frontend #JavaScript

To view or add a comment, sign in

Explore content categories