Invental/Review lessons/Code that silently does the wrong thing

Code that silently does the wrong thing

Schemas that strip unknown keys hide bugs

A schema that strips unknown keys turns “forgot to add the field” into silent success; when you add a field to an API, check that the parse schema, not just the handler, knows about it.

01 · Before and afterThe pattern

TypeScript
const publicLink = z.object({ url: z.string(), key: z.string() });
// internal UI needs extra fields; declare them or zod silently drops them
const internalLink = publicLink.extend({ couponId: z.string().nullish() });

const body = internalLink.parse(await req.json()); // body.couponId now survives

02 · Run it on your appThe check

For the last field you added to an endpoint, is there a test that sends it and asserts it was stored?

If the honest answer is no or not sure, this is worth a look before it reaches production.

Want this checked on your code?

Tell us what you are building and what worries you. We match a senior reviewer to your code and confirm scope before anything starts.

— Get in touch
hi@invental.co ↗
— Or
— What to include

A link or short description of the code or system, what you want checked, your stack, and when you need the answer. No repository access is needed until scope is agreed.

— Or leave a note
We reply within one business day.