Skip to content

Reference ​

The reference describes the TypeRule language and its tools exactly as the compiler implements them. Every example on these pages has been type-checked, and most have been run, with the typerule command-line tool.

If you are new to TypeRule, start with the guide and the tutorial. Use the reference when you need the exact syntax of something, the full list of methods, or what an error message means.

The language ​

PageWhat it covers
Projects and modulestyperule.toml, files and module names, from … import …, the standard library, the tests/ and migrations/ folders
SyntaxIndentation, line continuation, comments, keywords, every kind of literal (5.40 EUR, 3 pcs, 1.50 EUR/pcs, 22%, 2026-11-21, 30 days), f-strings
Entitiesentity, record, trait, extend, enum, fields and their modifiers, relations, formulas and defaults, temporary entities, seeds, functions, events
TypesEvery type, with currencies and units: how amounts are added, multiplied, converted, rounded or refused
ExpressionsOperators, ?. and ??, if … else, when:, match, lambdas, statements, every collection, text, date and amount method, the built-in functions
Rulescheck, warn, unique, required when, where, frozen when … except … live …, defaults versus formulas
Flows and actionsState machines, actions, require, fail, events, emit and the outbox, reactions (on … enters, on … becomes, on … created, on … changes, before …)
Variables and connections[vars] and [connections] in typerule.toml, secrets, env.NAME, outbound: signed webhooks and emails delivered after the commit, attempts and failures
LedgersAppend-only ledgers, key / measure / attr, post to, automatic reversal, per-group checks, queries
SecurityRoles, permission rules, row conditions, hidden fields, separation of duties

Working with a project ​

PageWhat it covers
Testingtest, fixture, use, clock, as user:, expect, expect_error, expect_compile_error, patch
Migrations and changesSchema migrations (rename, convert, backfill, verify, provisional values, CSV staging tables) and governed data changes
MetricsCertified metrics and controls, fingerprints, metrics.lock
Views and boardsSaved views and kanban boards made in the web client: sharing with users, teams, roles or everyone, teams versus roles, moving cards through transitions, what a deploy does to them
Apps and dashboardsApps made in the web client: a canvas of components, spreadsheets whose formulas are TypeRule expressions over the database (cell references, ranges, other sheets, spill), Markdown boxes, sharing, Excel export
CLIEvery typerule command and flag
HTTP APIAuthentication, queries, transactions, idempotency and conflicts, live events, the code-editor endpoints
StorageThe signed commit log, the SQL tables, loading on demand, optimistic concurrency, SQLite and PostgreSQL

Conventions used here ​

  • Code blocks marked typerule are TypeRule source. Small fragments (a single field, a single expression) are written as they appear inside an entity or a function.
  • Many examples are excerpts of the two example projects of the repository: examples/minimal (customers, products, orders, stock, in one file) and examples/extended (a complete ERP: sales, purchasing, inventory, manufacturing, accounting, invoicing). Their messages are translated here; the code is the same.
  • Error and warning messages are quoted exactly as typerule check and typerule test print them.
  • ::: warning boxes mark behaviour that is accepted by the compiler but does not (yet) do what the syntax suggests. Read them before you rely on the feature.

TypeRule: the books balance.