🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
🕵️ SicherheitslückenBurn Out, Or Fade Away(14.09.2026 um 14:25 Uhr)
🪟 Windows TippsSamsung-Galaxy-S26-Smartphones könnten ab Oktober teurer werden(15.09.2026 um 14:57 Uhr)
🪟 Windows TippsKB5129194 Windows 11 26H1 Out of Band Update - Deskmodder.de(14.09.2026 um 19:25 Uhr)
🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
🕵️ SicherheitslückenBurn Out, Or Fade Away(14.09.2026 um 14:25 Uhr)
🪟 Windows TippsSamsung-Galaxy-S26-Smartphones könnten ab Oktober teurer werden(15.09.2026 um 14:57 Uhr)
🪟 Windows TippsKB5129194 Windows 11 26H1 Out of Band Update - Deskmodder.de(14.09.2026 um 19:25 Uhr)

🔧 Programmierung 🕛 vor 2 Monaten 2 Min Lesezeit
0

Generate TypeScript Types from JSON (and where the auto-generators trip up)

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

You've got a JSON API response and you want TypeScript interfaces for it. Here's how to generate them fast — and where the auto-generators quietly get it wrong.






The fast path



Paste your JSON, get interfaces:




CODE
{ "id": 1, "name": "Ada", "roles": ["admin"], "profile": { "active": true } }











CODE
interface Root {
id: number;
name: string;
roles: string[];
profile: Profile;
}
interface Profile {
active: boolean;
}






jsonviewertool.com/json-to-typescript does this in the browser (client-side), nesting objects into their own interfaces.






Where generators trip up



A generator only sees the ONE sample you give it, which causes predictable gaps:





  • Nullable fields. If your sample has "avatar": null, the generator infers null — but the real type is probably string | null. Feed it a populated sample, or fix it by hand.


  • Empty arrays. "tags": [] infers any[] — the element type is unknowable from an empty array.


  • Optional fields. A field missing from your sample won't appear at all. If the API sometimes omits middleName, mark it middleName?: string.


  • Unions. A status that's "active" in your sample becomes string, not the literal union "active" | "banned" | "pending". Narrow it manually for the safety.


  • Numbers that are really enums or IDs. "currency": 840 types as number; you may want an enum or branded type.






When to use a schema instead



If the JSON has a JSON Schema or OpenAPI spec, generate types from that (json-schema-to-typescript, openapi-typescript) — it encodes nullability, optionality, and unions the raw sample can't. Sample-based generation is for quick throwaway typing; schema-based is for anything you'll maintain.






Rule of thumb



Generate from a sample to skip the boilerplate, then read every field — the generator gives you a draft, not a contract. Nullability and optional fields are where the runtime bugs hide.

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
The Gemini desktop app is now available for Windows
1 Quelle
Burn Out, Or Fade Away
1 Quelle
Windows 11 KB5129195 is out after Microsoft confirms major issues with the September 2026 update, but it won’t fix AMD GPU errors
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Generate TypeScript Types from JSON (and where the auto-generators trip up)

Thematisch verwandte Begriffe: Generate, TypeScript, Types, from · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...