How to Convert TypeScript to Go - Step by Step

Step 1

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.

•
Paste directly: copy interfaces from your frontend code, API definitions or a shared types file
•
Upload a file: pick a .ts or .tsx file; the converter reads the interface, type and enum declarations in it
•
Try the sample: click Sample to see a User interface with a nested object and a string union convert 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;
  };
}
Step 2

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:

•
Primitives: string → string, number → float64, boolean → bool, bigint → int64
•
Arrays and maps: T[] and Array<T> become []T; Record<string, V> and index signatures become map[string]V
•
Nested objects: an inline object type becomes its own named Go struct
•
Optional and nullable: field?: T and T | null become a pointer *T with ,omitempty
•
Field names: property names become exported Go identifiers (user_id → UserID), kept unique within a struct

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"`
}
Step 3

The JSON Tags Option

There is one option: the JSON Tags toggle. A couple of things happen automatically and aren't separate settings:

•
JSON Tags (toggle): on by default; turn it off to get plain structs with no json tags
•
Field naming (automatic): property names are exported for you (PascalCase, with Go initialisms like ID and URL) so JSON marshaling works
•
omitempty (automatic): optional fields get the ,omitempty tag so a nil pointer is left out of the JSON
Step 4

Copy or Download the Go

When the output looks right, take it into your project:

•
Copy to clipboard: paste straight into a Go source file
•
Download as types.go: save the generated code as a .go file
•
The badge: a green "Converted" badge means the TypeScript parsed and Go was produced; a red "Error" badge shows the line and column that stopped it

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

TypeScript Interfaces Documentation

Official TypeScript handbook on interfaces and types

Effective Go

Essential guide to writing clear, idiomatic Go code

JSON and Go

Official Go blog on working with JSON encoding and struct tags

Go encoding/json Package

Official documentation for JSON marshaling in Go

Go by Example: Structs

Practical examples of Go structs and their usage