Skip to main content
TypeScript

JSON to TypeScript interfaces: use generated types without lying to yourself

Generated TypeScript interfaces accelerate API work, but they describe a sample—not runtime truth. Generate a starting point, then add validation and model optionality deliberately.

Thien Nguyen
By Thien Nguyen
Updated June 11, 2026 · 1 min read

Paste JSON into a generator and you get a pleasing interface in seconds. That speed is useful, as long as you remember the generated type is inferred from one sample and TypeScript erases it at runtime.

Short answer: generate types to remove mechanical typing, then review nullable fields, arrays, IDs, timestamps, and unions. Validate untrusted JSON at the boundary; an interface cannot stop an API from returning the wrong shape.

interface Order {
  id: string;
  totalCents: number;
  createdAt: string; // parse as a date at the boundary
  items: Array<{ sku: string; quantity: number }>;
}
Sample valueQuestion to ask
nullIs null meaningful or was it absent?
[]Are elements uniform?
"2026-07-21"Date-only or timestamp?
"paid"Closed enum or arbitrary string?

as Order is a type assertion, not validation. It tells the compiler to trust you; it does not inspect one byte of JSON.

Start with the JSON to TypeScript generator, then put a schema validator at the network boundary and map the external payload to your internal model. Generated types are scaffolding, not a contract.

Cover photo by Seraphfim Gallery on Pexels.

References

Primary documentation and specifications checked when this article was last updated.

TypeScriptJSONAPIs

Related articles

All articles