Menu

Four runtime bugs that pass tsc: what to look for when you review AI-written TypeScript
📰

Four runtime bugs that pass tsc: what to look for when you review AI-written TypeScript

DEV Community: nextjs·Souk Code·10 days ago
#okEC4BsC
#devtonextjs#devto#dev#number#quantity
Long article (994 words) — no AI summary yet.
Reading 0:00
15s threshold

When an AI assistant writes a route handler for you, it compiles. That is the easy part. The bugs that survive a quick review are the ones the compiler cannot see: values that have the right type on paper and the wrong value at runtime.

This post is for developers who already review AI-assisted diffs (or write TypeScript for APIs) and want a short list of runtime traps to check for. Each one is a script you can paste and run. Nothing here is a benchmark or a claim about how often any tool makes these mistakes. These are shapes I look for in review, and I ran every snippet below on Node 22.

1. as is not validation

A handler reads JSON and asserts the type:

type CreateItem = { name : string ; quantity : number ; unitPriceCents : number } ;

// 1. A type assertion does not check anything at runtime. const body : unknown = JSON . parse ( '{"name":"Pen","quantity":"5","unitPriceCents":250}' ) ; const item = body as CreateItem ; console . log ( "1 total:" , item . quantity * item .…

Continue reading — create a free account

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