0PricingLogin
Zig Academy · Lesson

Building Types with @Type

Construct new types programmatically.

The Reverse of @typeInfo

If @typeInfo turns a type into data, @Type turns data back into a real type. Together they let you reshape types at compile time. 🛠️

Feed It a Type.Info Value

@Type takes a std.builtin.Type value and produces the concrete type it describes. You hand it a description, it gives you a type.

const T = @Type(.{ .Int = .{ .signedness = .unsigned, .bits = 8 } });

All lessons in this course

  1. Reflecting Fields with @typeInfo
  2. Building Types with @Type
  3. Comptime Validation and @compileError
  4. Generating Code with comptime
← Back to Zig Academy