Go Structs to TypeScript Interfaces
Paste Go struct definitions and get TypeScript interfaces that follow the json tags: omitempty makes a property optional, pointers become | null, slices become arrays and embedded structs become extends.
Use the tool
Why this tool exists
A Go API returns JSON shaped by struct tags, and the TypeScript client has to model the same names and optionality. Reading the tags and translating by hand is where mistakes creep in.
The converter follows what encoding/json does: it uses the tag name (or the field name when there is none), drops json:"-" and unexported fields, treats omitempty as optional, pointers as nullable, []byte as a base64 string and time.Time as a string, and inlines embedded structs through extends. Constant groups of typed strings or iota values become unions or enums. The result was type-checked with tsc against JSON produced by a real Go program. Everything runs in your browser and nothing is uploaded.
How to use it
- Paste your Go type declarations. Package and import lines can stay.
- Choose how constants, time.Time and nil slices are mapped.
- Copy the TypeScript into your front end project.
Frequently asked questions
What does it not see?
Custom MarshalJSON methods, build tags, types from other packages (which become unknown with a comment) and generic constraints. It reads declarations only and never runs Go.
Why is int64 a number?
JSON.parse returns a JavaScript number, which is exact only up to 2^53. Fields tagged with ,string become string. For larger values handle the field by hand.
What about nil slices?
A nil slice without omitempty marshals as null. Turn on the nil slices option to type those fields as T[] | null.
How are embedded structs handled?
An embedded struct without a json tag has its fields promoted into the parent in JSON, so the interface extends it. With a tag name it becomes an ordinary property.