Types and literals#
Type expressions describe values, declarations, parameters, table fields, messages, validation functions, and service APIs.
Built-in types#
The grammar recognizes these built-in families:
| Family | Types |
|---|---|
| Text | string, text, email, phone, url |
| Integer | integer, int, long, uint, ulong |
| Number | float, double, decimal, number, percentage, percent |
| Boolean | boolean, bool |
| Time | datetime, timestamp, date, time, duration |
| IDs | uuid, node_id, guid |
| Payload | json, blob, xml |
| Media/location | coordinate, geolocation, color, image, file |
| Pattern | regex, pattern_type |
| Control | void |
Nullable and array types#
struct TypeExamples {
field optional_vendor_id: VendorId?;
field line_amounts: decimal[];
field matrix: decimal[][];
}Unions and intersections#
type ExternalId: string | uuid;
type AuditedCustomer: Customer & AuditedRecord;Generics#
Generic arguments can use angle brackets or square brackets.
field page: Page<Customer>;
field lookup: Map[string, Customer];Type declarations do not currently accept declaration-site generic parameters. Use generic arguments at reference sites.
type CustomerResult {
value: Customer;
}
type CustomerPage: Page<Customer>;Function, reference, tuple, and mapped types#
field predicate: (Customer) -> bool;
field callback: function(Customer, decimal): bool;
field customer_ref: ref<Customer>;
field pair: (string, decimal);
field projection: { [K in Keys]: string };Conditional types#
type Output: SourceValue extends string ? TextOutput : JsonOutput;Operator and suffix order#
Type expressions support union |, intersection &, conditional T extends U ? A : B, suffixes such as [] and ?, literal parameters, and generic arguments.
type MaybeIds: string[] | uuid[]?;
type AuditedResult: AuditedRecord extends Audited ? Result<AuditedRecord> : ErrorResult;
struct TypeSuffixExamples {
field sized_code: string(40);
field page: Page<Customer>;
}Function types accept ->, =>, and function(...): Return forms.
field predicate: (Customer) -> bool;
field mapper: (Customer) => Json;
field callback: function(Customer, decimal): bool;Type literal parameters#
Some types accept literal parameter lists or ranges.
type ExternalCode;
type Money: decimal(18, 2);
field amount: decimal(0..1000000);
field bounded_percent: decimal(0..100);
field code: string(40);Literals#
let double_quoted = "double quoted";
let single_quoted = 'single quoted';
let template_text = `template text`;
let decimal_value = 123;
let hex_value = 0xFF;
let binary_value = 0b1010;
let float_value = 12.34;
let scientific_value = 1.2e5;
let percent_value = 25%;
let enabled = true;
let disabled = false;
let empty_value = null;
let date_value = Date("2026-04-26");
let time_value = Time("10:30");Arrays and objects#
let empty = [];
let values = [1, 2, ...more_values];
let payload = {
name: "Vendor",
amount: 100,
[dynamic_key]: true
};Object properties can be separated with commas or semicolons.