typeover
curriculum

Curriculum Types Structs exercise 3 · mcq

Structs

TypeScript attaches methods inside the type / class. Zig attaches methods INSIDE the struct, declared with pub fn and an explicit self parameter (Python style — named, not implicit). Pick the right Zig shape.

TypeScript reference
Pick the idiomatic Go translation

About this theme

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 }); access is .x (no surprise). Methods are declared INSIDE the struct as pub fn name(self: SelfType, ...) ReturnType — same shape as Go, but with the explicit self: parameter named like Python. No inheritance, no implicit this.