0PricingLogin
Zig Academy · Lesson

@TypeOf and Type Reflection

Inspect types to stay generic.

Asking About Types

Generic code often needs to know the type of a value without you spelling it out. Zig answers that with the built-in @TypeOf. 🔍

@TypeOf Returns a Type

Give @TypeOf one or more expressions and it returns their type, computed entirely at compile time.

const T = @TypeOf(value);

All lessons in this course

  1. Functions That Take a Type
  2. Generic Data Structures
  3. @TypeOf and Type Reflection
  4. anytype Parameters
← Back to Zig Academy