typeover
curriculum

Curriculum Types

module 2 of 4

Types

Zig's type vocabulary is similar enough to TypeScript that you can lean on the analogues — struct matches object literals, enum matches string literal unions, union(enum) matches discriminated unions. The diverging bits are pointers (*T, *const T, [*]T, ?*T — each meaning something specific) and arrays vs slices ([N]T length-in-type vs []T slice). Lays the type foundation that Memory + Errors + Comptime build on.


themes

Zig structs are TypeScript object literals' closest cousin: const Point = struct { x: i32, y: i32 };. Instantiation uses dot-prefixed field initializers (`Point{ .x = 3, .y = 4 }…

9 ready begin →

TypeScript reaches for string-literal unions ("red" | "green" | "blue") for enums and discriminated unions ({ kind: "circle", radius: 5 } | { kind: "square", side: 3 }) for sum…

9 ready begin →

TypeScript has no pointer syntax — everything is a reference under the hood. Zig has dedicated syntax for pointers, and several flavours: *T (single pointer to one T), *const T

9 ready begin →

Zig has two collection shapes where TypeScript has one. [N]T is a fixed-length array; the length N is part of the type, known at compile time. []T is a slice: a pointer plus a runt…

9 ready begin →