GUIDE深度 · Deep dive
JSON to TypeScript: interface or type
Objects usually use interface; unions/aliases/arrays use type; they are interchangeable in many cases. The hard part is expressing optional fields, null, array element types and nested objects, plus runtime validation.
Choosing
Objects/extensible: interface.
Unions/mapped/aliases: type.
Array elements: `Item[]`.
Do not miss
Missing keys → `?`.
Possible null → `| null`.
Empty arrays → define the element type first.
FAQ
Can I use the generated types directly?
As a starting point; add unions/validation/docs for production.
Why runtime validation?
TS types disappear at runtime; external JSON may still mismatch.