Golang for TypeScript devs

Just a guy who loves to write code and watch anime.
Search for a command to run...

Just a guy who loves to write code and watch anime.
No comments yet. Be the first to comment.
Qualities that make outstanding builders.

Bipedal vs quadrupedal: how many legs This is about the number of legs the creature walks on. Bipedal. Two legs. Humans, ostriches, T-rex, kangaroos, most fantasy humanoids. Quadrupedal. Four legs. Do

Intro You hear "lerp" and "smoothstep" everywhere in game dev. They sound like math jargon. They're not. Both are small tools that do the same job: smoothly move from one value to another. The problem

What is Kinematics Kinematics is the math field. It's the study of how things move without worrying about forces (which would be dynamics). FK and IK are the two branches: forward kinematics and inver

Intro Textures are usually the biggest cost in a 3D scene. Memory, bandwidth, and load time all get eaten by them. Resizing them is the obvious lever. There's more. This post is about the less obvious

TypeScript:
let name: string = "john";
const age: number = 25;
let active: boolean = true;
let items: string[] = ["a", "b"];
Go:
var name string = "john" // or: name := "john"
const age int = 25
active := true
items := []string{"a", "b"}
TypeScript:
function add(a: number, b: number): number {
return a + b;
}
const multiply = (a: number, b: number): number => a * b;
Go:
func add(a int, b int) int {
return a + b
}
// Go doesn't have arrow functions, just regular functions
func multiply(a, b int) int {
return a * b
}
TypeScript:
try {
const result = riskyFunction();
} catch (error) {
console.log(error);
}
Go:
result, err := riskyFunction()
if err != nil {
log.Println(err)
}
TypeScript:
const response = await fetch("https://api.example.com/data");
const data = await response.json();
Go:
resp, err := http.Get("https://api.example.com/data")
if err != nil {
return err
}
defer resp.Body.Close()
var data interface{}
json.NewDecoder(resp.Body).Decode(&data)
TypeScript:
// For loop
for (let i = 0; i < 10; i++) {}
// Array iteration
items.forEach((item) => console.log(item));
// For...of
for (const item of items) {
}
Go:
// For loop
for i := 0; i < 10; i++ {}
// Slice iteration
for _, item := range items {
fmt.Println(item)
}
// With index
for i, item := range items {
fmt.Printf("%d: %s\n", i, item)
}
TypeScript:
interface User {
name: string;
age: number;
}
const user: User = { name: "john", age: 25 };
Go:
type User struct {
Name string `json:"name"`
Age int `json:"age"`
}
user := User{Name: "john", Age: 25}
TypeScript:
const jsonStr = JSON.stringify(obj);
const obj = JSON.parse(jsonStr);
Go:
jsonBytes, _ := json.Marshal(obj)
jsonStr := string(jsonBytes)
var obj MyStruct
json.Unmarshal([]byte(jsonStr), &obj)
TypeScript:
if (condition) {
// do something
} else if (other) {
// do other
} else {
// default
}
const result = condition ? "yes" : "no";
Go:
if condition {
// do something
} else if other {
// do other
} else {
// default
}
// No ternary operator, use if/else
var result string
if condition {
result = "yes"
} else {
result = "no"
}
TypeScript:
const items = [1, 2, 3];
items.push(4);
const filtered = items.filter((x) => x > 2);
const mapped = items.map((x) => x * 2);
Go:
items := []int{1, 2, 3}
items = append(items, 4)
// No built-in filter/map, write loops
var filtered []int
for _, x := range items {
if x > 2 {
filtered = append(filtered, x)
}
}
TypeScript:
const text = `Hello ${name}`;
const parts = text.split(" ");
const joined = parts.join("-");
Go:
text := fmt.Sprintf("Hello %s", name)
parts := strings.Split(text, " ")
joined := strings.Join(parts, "-")
TypeScript:
async function fetchData() {
const result = await someAsyncFunction();
return result;
}
Promise.all([fetch1(), fetch2()]);
Go:
func fetchData() (string, error) {
// Go doesn't have async/await
// Use goroutines for concurrency
return someFunction()
}
// Concurrent execution
ch := make(chan string, 2)
go func() { ch <- fetch1() }()
go func() { ch <- fetch2() }()
result1, result2 := <-ch, <-ch
No classes → Use structs and methods
No null/undefined → Use zero values and pointers
Explicit error handling → No try/catch, check err != nil
No generics (until Go 1.18+) → Interface{} or code generation
Package system → Import paths, not node_modules
Compiled → go build creates binary
Garbage collected but more explicit about memory
Goroutines instead of async/await