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 value | Question to ask |
|---|---|
null | Is null meaningful or was it absent? |
[] | Are elements uniform? |
"2026-07-21" | Date-only or timestamp? |
"paid" | Closed enum or arbitrary string? |
as Orderis 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.
