Start with representative data

Type inference is only as complete as the sample. Include empty arrays, nullable properties and multiple variants when possible so a generator can see the shapes your frontend must handle.

Separate static types from runtime validation

TypeScript types disappear at runtime. They help editors and builds, but cannot prove that a network response is valid. Use a runtime schema such as Zod at untrusted boundaries, then infer the TypeScript type from that schema when appropriate.

  • Generate interfaces for developer ergonomics.
  • Validate external input before trusting it.
  • Model nullable and optional fields deliberately.
  • Keep API DTOs separate from UI view models.

Review generated unions

Mixed arrays can produce broad unions. That output is safer than silently choosing the first item, but it may indicate inconsistent source data that deserves a backend contract.

Primary references

Read the specification

TypeScript DocumentationTypeScript for the New ProgrammerJSON SchemaJSON Schema Draft 2020-12

Put the guide into practice

Open the related browser tools and test the workflow with a synthetic sample

JSON to TypeScript JSON to Zod JSON to JSON Schema