Guide 26 of 53
Static type queries
Use an expression's checked type without executing the expression.
A typeof annotation uses the statically checked type of an expression. The
operand does not run, including a function call written inside the query.
let defaults = .{ host: "localhost", attempts: 3 }
type Options = typeof defaults
fn describe(options: Options) -> str =
"{options.host}: {options.attempts} attempts"
let production: Options = .{ host: "api.example.com", attempts: 5 }
print(describe(production))Options retains the record's field names and types. A numeric host is a type
error. Write typeof (expression) when querying an arithmetic or conditional
expression; a bare operand supports references, fields, indexing and calls.
The checker resolves global initializers and function signatures without evaluating them. Cyclic queries are diagnosed. The formatter preserves the query, while the compilation pipeline replaces it with its checked annotation.
Queries cannot currently synthesize annotations for opaque machine ownership, dimensional quantities, open effect rows, or callable defaults/reification witnesses. These forms receive a diagnostic rather than losing their contract. Foreign headers require explicit types before provider translation.
DOCS / FEEDBACK
Did this page leave a question?
Tell us where the explanation lost you. Documentation is part of the language experience.