Urgent.News

What's breaking now, across thousands of outlets.

Tech

Stop hand-writing TypeScript interfaces from API responses. Seriously.

I kept a file in one project called types.ts that was substantially a transcription service. Every time the backend added or changed a response shape, I'd paste the sample JSON into a comment and hand-write an interface underneath it. Two problems with this, both expensive: it was slow, and it was optimistic — I typed fields as string that were sometimes null , marked things required that the API…

Stop hand-writing TypeScript interfaces from API responses. The author of this story kept a file called types.ts in their project, where they transcribed JSON responses into hand-written interfaces. They shared two issues with this approach: it was time-consuming and relied on optimistic typing, which often led to incorrect assumptions about field types and whether fields were required or optional.

The author's solution was to use a tool called TypeGen, which takes JSON or CSV payloads as input and generates clean TypeScript interfaces, type aliases, or a Zod schema. What sets TypeGen apart is its ability to explain its inferred assumptions and flag ambiguous fields, such as fields that are sometimes null or mixed-type, for manual review.

The author emphasizes that inference is just the first step, not the final one. After generating interfaces with TypeGen, they recommend reviewing the ambiguous fields and adjusting the inferred types accordingly. They also mention that Zod schema export can catch runtime shape mismatches that TypeScript types might miss. The author stresses that inference is only as good as the sample data provided - feeding the tool only happy-path responses won't account for cases where fields might be missing.

They caution that TypeGen infers structure but not semantics, so it won't understand that certain fields, like expiry dates, have specific business rules. The author also notes that CSV inference is inherently less accurate than JSON inference. The story concludes with a five-minute test: paste a challenging API response into TypeGen and compare its generated interfaces and ambiguous-field list to your hand-written interfaces.

If there are discrepancies, you're likely to find errors in either the generated code or your memory.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

CVE-2026-96889: Next.js Image Optimization RCE Vulnerability — Analysis & Mitigation

Originally published at https://faizanakhtarcyber.blogspot.com/2026/10/cve-2026-96889-nextjs-image-optimization-rce-analysis.html On October 14, 2026, Vercel shipped an out-of-band security release…

  • Vercel released emergency update on Oct 14, 2026 to fix CVE-2026-96889
  • Image Optimization API flaw allows remote code execution with no authentication
  • Vulnerable versions include all releases from 10.0.0 onward, affecting millions of sites

More from Saturday 17 October →