TS
GO

TypeScript to Go

10 lessons

Progress0%
1Introduction: Transpiled to Compiled Binary2Type Systems: Structural Interfaces3Functions4Objects to Structs5Generics6Error Handling7Async to Goroutines8Ecosystem9Testing10Go Standard Library
All Mirror Courses
TS
GO
Introduction: Transpiled to Compiled Binary
MirrorLesson 1 of 10
Lesson 1

Introduction: Transpiled to Compiled Binary

Introduction

Introduction

In this lesson, you'll learn about introduction: transpiled to compiled binary in Go. Coming from TypeScript, you already have a foundation for understanding this concept. We'll build on that knowledge while highlighting the key differences.

Mirror Card
TS
From TypeScript:

In TypeScript, you're familiar with introduction.

GO
In Go:

Go has its own approach to introduction, which we'll explore step by step.

The Go Way

Let's see how Go handles this concept. Here's a typical example:

GO
Go Example
// Go — compiles to a single native binary
package main

import "fmt"

func main() {
    greeting := "Hello, World!"
    fmt.Println(greeting)
    fmt.Println(add(2, 3))
}

func add(a int, b int) int {
    return a + b
}

Comparing to TypeScript

Here's how you might have written similar code in TypeScript:

TS
TypeScript (What you know)
// TypeScript — transpiles to JS, runs on Node.js
const greeting: string = "Hello, World!";
console.log(greeting);

function add(a: number, b: number): number {
  return a + b;
}

console.log(add(2, 3));
Mirror Card
TS
From TypeScript:

You may be used to different syntax or behavior.

GO
In Go:

Go compiles to a single self-contained native binary — no runtime required

Mirror Card
TS
From TypeScript:

You may be used to different syntax or behavior.

GO
In Go:

Every Go file belongs to a package; the entry point is package main with func main()

Mirror Card
TS
From TypeScript:

You may be used to different syntax or behavior.

GO
In Go:

:= is short variable declaration (type inferred)

Mirror Card
TS
From TypeScript:

You may be used to different syntax or behavior.

GO
In Go:

fmt.Println replaces console.log

Step-by-Step Breakdown

1. Single Native Binary

Go compiles directly to a native executable with no external runtime or interpreter. Deployment is a single binary — no node_modules, no JVM.

TS
TypeScript
tsc index.ts && node index.js
GO
Go
go build -o myapp main.go
./myapp  # single binary, no runtime needed
Rule of Thumb
go run main.go for development (compile + run). go build for production deployments.

2. package main and func main()

Every Go source file declares a package. The executable entry point is func main() in package main. Libraries use other package names.

TS
TypeScript
// TypeScript: top-level code runs directly
GO
Go
package main

func main() {
    // entry point
}

3. := Short Variable Declaration

:= declares and assigns a variable with inferred type. It can only be used inside functions. var is used at package level.

TS
TypeScript
const name = "Alice"; // inferred as string
let count = 0;
GO
Go
name := "Alice"  // inferred as string
count := 0       // inferred as int

// Or explicit:
var name string = "Alice"
Common Pitfall
:= cannot be used at package level — use var for package-level variables.

4. fmt Package

Go's fmt package handles printing and formatting. fmt.Println adds a newline. fmt.Printf uses format verbs like %s, %d, %v.

TS
TypeScript
console.log(`Hello, ${name}! You are ${age} years old.`);
GO
Go
fmt.Printf("Hello, %s! You are %d years old.\n", name, age)
// or with fmt.Sprintf for string formatting:
msg := fmt.Sprintf("Hello, %s!", name)

Common Mistakes

When coming from TypeScript, developers often make these mistakes:

  • Go compiles to a single self-contained native binary — no runtime required
  • Every Go file belongs to a package; the entry point is package main with func main()
  • := is short variable declaration (type inferred)
Common Pitfall
Don't assume Go works exactly like TypeScript. While the concepts may be similar, the syntax and behavior can differ significantly.

Key Takeaways

  • Go compiles to a single native binary — no runtime or interpreter needed
  • Entry point is func main() in package main
  • := declares and infers type in one step
  • fmt.Println/Printf replaces console.log
Rule of Thumb
The best way to learn is by doing. Try rewriting some of your TypeScript code in Go to practice these concepts.
OverviewNext