How to Convert TypeScript to Go - Step by Step
Paste Your TypeScript
Drop in the interfaces, types or enums you want in Go. This is handy when a Go backend has to read JSON that a TypeScript frontend produces, or when you are porting shared models from TypeScript to Go.
Example: TypeScript interface input
A typical interface you might share between a frontend and a Go service:
interface User {
id: number;
username: string;
email: string;
age?: number;
isActive: boolean;
role: "admin" | "user" | "guest";
tags: string[];
metadata: {
createdAt: string;
updatedAt: string;
};
}How the Types Map to Go
Each interface becomes a struct, and the converter keeps your property names in the json tags so encoding/json round-trips the same JSON:
Example: generated Go
The same interface, as gofmt-aligned structs (the nested object became its own Metadata struct):
package main
type User struct {
ID float64 `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
Age *float64 `json:"age,omitempty"`
IsActive bool `json:"isActive"`
Role string `json:"role"`
Tags []string `json:"tags"`
Metadata Metadata `json:"metadata"`
}
type Metadata struct {
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
}The JSON Tags Option
There is one option: the JSON Tags toggle. A couple of things happen automatically and aren't separate settings:
Copy or Download the Go
When the output looks right, take it into your project:
Frequently Asked Questions
How does the converter handle TypeScript union types?
A union of string literals, like "admin" | "user" | "guest", becomes a Go string since every value is just text. A union of number literals becomes int (or float64 when any member has a fraction). A union of genuinely different types, such as string | number, has no single Go type, so it becomes interface{} and the output adds a note so you can narrow it by hand.
Can I convert a TypeScript class to Go?
Classes are not read. Pull the data fields out into an interface first, then convert that. Methods and constructors have no struct equivalent, so you rewrite those as Go functions or struct methods yourself.
What about Array<T>, Record<K, V> and generics?
Array<string> and string[] both become []string. Record<string, V> and an index signature ({ [k: string]: V }) both become map[string]V. A standalone type parameter T has no fixed shape, so it maps to interface{} with a note. Promise and function types are not data and also become interface{}.
Why do optional fields become Go pointers?
A pointer (*T) can be nil, which is the only way to tell "the field was absent" from "the field held its zero value". So age?: number becomes Age *float64 with a ,omitempty tag, and a field typed string | null becomes a pointer too.
Does it keep big integer IDs exact?
A TypeScript number is a 64-bit float, so it maps to Go float64 and a value past 2^53 would round — the same limit TypeScript itself has. If you need every digit of an ID, declare it as bigint in TypeScript: that maps to Go int64, which holds the full value.
Is it free, and where does my code go?
It is free, and the whole conversion runs in your browser. Your TypeScript is never uploaded and nothing is kept, so reloading the page starts with an empty editor.
External Resources & Documentation
Official TypeScript handbook on interfaces and types
Essential guide to writing clear, idiomatic Go code
Official Go blog on working with JSON encoding and struct tags
Official documentation for JSON marshaling in Go
Practical examples of Go structs and their usage
Related Tools
JSON to Go
Convert JSON data to Go structs with json tags
JSON Schema to Go
Generate Go types from JSON Schema with validation
YAML to Go
Convert YAML configuration to Go structs with yaml tags
TOML to Go
Convert TOML configuration to Go config structs
XML to Go
Convert XML data to Go structs with xml tags
CSV to Go
Convert CSV data to Go structs with field mapping