Alright, so I decided to mess around with Tygo today. I’d heard about it as a way to generate TypeScript definitions from Go structs, and I was curious to see how well it actually worked. I’ve been working on a project with a Go backend and a TypeScript frontend, and keeping the types in sync has been, let’s just say, a challenge.

First, I installed it. It was pretty straightforward, just a simple go install command, You know:
go install */gzuidhof/tygo
I then made sure it was working by checking the version.
tygo -version
And that’s it! It’s already installed.

Next, I navigated to the directory with my Go code. I have this file, , with a bunch of structs that I use for my API responses. I wanted to see if Tygo could handle all of them in one go. I figured that’s the real test, right? Not just one simple struct, but a whole bunch of them, nested and all.
My First Attempt
I bravely typed:
tygo *
…and hit Enter. The command line whirred for a second, and then, BAM! A new file appeared: . I opened it up, and…wow. It was all there. All my Go structs, neatly translated into TypeScript interfaces. It even handled the embedded structs correctly, which I was a little worried about.
Adding Some Comments for Clarity
Okay, so that was cool, but I wanted to make the generated TypeScript a bit more readable. I went back to my file and added some comments above the struct fields, you know, just regular Go comments. Like this:

type User struct {
// The user's unique identifier.
ID string `json:"id"`
// Email string `json:"email"`
Then I ran Tygo again:
tygo *
And checked the output. Nice! The comments were right there in the TypeScript interfaces, making everything much clearer. This is actually usable!
Dealing with JSON Tags
Most of my structs have JSON tags to control how they get serialized and deserialized. Like, I might have a field named “CreatedAt” in Go, but I want it to be “created_at” in the JSON. Tygo handled these perfectly by default. It just used the JSON tag name in the TypeScript interface. Smart.
My overall experience
So, after playing around with Tygo for a few hours, I’m pretty impressed. It did exactly what it promised, and it did it well. It saved me a ton of time and headache, and it’s definitely going to be part of my workflow from now on.
If you’re working with Go and TypeScript, you should check Tygo!