Posts

Showing posts with the label TypeScript

tRPC: Your API and Your Client, Sharing One Type

Image
Every team that builds a TypeScript API hits the same frustration. The server changes a field name, or a procedure starts expecting a different argument, and the client keeps calling the old shape. Nothing complains until a user hits the broken page in production. The usual fix is a shared schema file, a code generator, or an OpenAPI document that someone has to remember to regenerate. tRPC takes a different route. It skips the schema file entirely and lets the client import the server router type, so the editor knows exactly which procedures exist and what each one accepts. The question is what it costs in practice, and whether the trade is worth it for a small team. Quick answer Yes, tRPC is worth it when the client and server are both TypeScript and the API is only for your own frontend. It lets the client import the server router type, so the editor knows exactly which procedures exist and what each one accepts, and a renamed field shows up as a red squiggle the same afternoon. T...

Drizzle ORM: Your Database Schema, Written in TypeScript

A small ceramics shop renamed one column. The orders table had a column called customer, and someone renamed it to customer_id. The shop's code built its queries by joining strings together, so nothing complained. The first sign of trouble came from a customer, whose order page showed a blank where her name should have been. The query had failed quietly, and nobody noticed until she did. That is the problem an ORM is supposed to solve: the database and the code should agree about the shape of the data, and a rename should break loudly at build time instead of quietly in production. Drizzle ORM takes an angle on that promise, and this post tests whether it holds up. Quick answer Yes, Drizzle is the right call when you like SQL and want the compiler to watch your back, because you write your schema in TypeScript and the queries look a lot like SQL, with select, eq, and innerJoin. On a small ceramics shop it totaled two orders, $78 and $73.5, with row.total a number and row.customer...

Zod: Stop Bad Data at the Door of Your Checkout

A customer fills in a checkout form and picks two ceramic mugs and a linen tote. Somewhere between the form and the server, the quantity turns into the string "2" instead of the number 2. TypeScript does not catch it, because TypeScript checks code before it runs, not data arriving while the program is live. The server adds the quantity to the total and the maths produces nonsense, or the order saves with a quantity nobody can fulfil. The bug is not in the form or in the maths. It is in the gap between what the code expects and what actually arrives. Zod closes that gap: describe the shape of the data once, and check every order against it. For the language underneath TypeScript, see JavaScript Explained: The Language That Runs the Whole Web . Quick answer Yes, Zod is worth adding the moment your code receives data it did not create, because you describe the shape of the data once as a schema and Zod checks every order against it before your code trusts it. A form that sent...

NestJS Explained: Node Backends With Structure Built In

A small Node back end starts as one file with a handful of routes, and it works fine. Then the second feature arrives, and the third, and the routes file grows into a thousand lines where database code, validation, and HTTP handling all live together. Quick answer Yes, pick NestJS when the back end will grow past a few routes and the team already writes TypeScript, because NestJS organises a Node back end into modules, controllers, and providers, and wires them together with dependency injection. The library example lists three books and lets volunteers borrow one, refusing a second borrow of Braiding Sweetgrass with a 400 once its single copy is gone. Do not pick it for a tiny API or a quick prototype, since plain Express is less to learn and faster to start for a handful of endpoints. NestJS is a framework for building Node back ends in TypeScript, with structure built in. It organises code into modules, controllers, and providers. A controller handles HTTP, a service holds the bu...

Prisma Explained: Databases Without Writing Raw SQL

A studio keeps its work in three places: clients in a spreadsheet, projects in a notes app, invoices as PDFs. Answering one question, which clients still owe money, means opening all three and matching names. The next step is a database, and that brings the second problem: every query becomes a SQL string in the code, and a typo in a column name only fails when that line runs. Prisma is built for that gap. You describe the tables once, in a schema file, and Prisma gives you a typed client to query them with, so the editor catches a misspelled field before the code runs. No raw SQL for everyday queries, and the database still holds the real data. Drizzle ORM: Your Database Schema, Written in TypeScript is another way to describe tables in code. Quick answer Prisma lets you describe your tables once in a schema file, and generates a typed client to query them with, so the editor catches a misspelled field before the code runs. It fits a small team whose data is relational, like clien...

TypeScript Explained: Types That Catch Bugs Before They Run

A function expects a list of orders, and somewhere upstream one of them arrives with its total as a string instead of a number. In plain JavaScript nothing complains. The code runs, the total comes out wrong, and the first person to notice is a customer looking at a wrong invoice. That is the gap TypeScript exists to close. It checks, while you are still writing, whether the shapes of data you pass around match the shapes you said you expected, and it tells you the moment they do not. You describe an order once, as an object with an id, a total, and a paid flag, and every function touching orders must agree with that description. Quick answer TypeScript is JavaScript with types added. You describe the shape of your data once, and the checker warns you in the editor when code passes the wrong shape, so many bugs are caught before the program runs. What I would check before using it My judgement, from years of writing and reviewing typed and untyped JavaScript, is this: adopt TypeScrip...