This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index at /llms.txt, or add .md to any page's URL.
Values, expressions, and functions
An expression Contract accepts means what the same TypeScript means, except as
this table says (LLP 1116.016 D1; semantics/corpus/typescript/ checks each
against JavaScript), and a TypeScript form Contract refuses is refused with
what to write. Nothing runs because a value changed (no useEffect or watch).
Contract | Because |
|---|---|
No truthiness: a condition is a bool (if name != "") | every condition says what it tests |
Absence is an option (none, some(x), match), not undefined or null; no ?? or ?. | a value whose type has no absence is never absent |
A value never changes: no push, sort, xs[i] = …; concat, a record copy | an action is one transaction |
== compares lists and records by value; no === | values have no identity |
A string is well-formed: a lone surrogate becomes U+FFFD ("😀".slice(0, 1)) | every host holds Unicode scalar values |
A stored number is finite: a commit that would put NaN or Infinity in a state or derive is refused, and the write that caused it does not land | every host can carry it |
A resource or send argument must contain only finite numbers, including inside lists, records and options; the runner refuses the call before asking its source and names the argument position | Rust and TypeScript sources accept the same values on every host, whether placed on the main thread or a worker |
toFixed and the format functions print "" for a non-finite number | one rule for every format |
Names hold hyphens, so subtraction takes spaces (a - b) | CSS's names |
A binding's list work is bounded (65,536 steps); a row's own binding has its own bound, so a row that searches another table costs rows × items (lower-row-lookup), and one that walks its own for's list grows with it until the binding is unset (lower-row-own-list) | determinism on every host |
No comparator sort: sortBy(xs, x => key) orders by one number or string key, stably ("desc" third; a second key is an earlier sortBy). Grouping, joining, aggregates and a stored or locale order are the data module's; the view names an order it relies on where it reads it (loadTasksByDueDate()) | a view computes what it shows, the same on every host |
•
Types are number, string, bool, declared shapes, option<T>, T[],
and action for behavior interfaces. Do not emit authored any or object types.
•
[a, b, c] is a list of its items, which may span lines and keep a trailing
comma; the items have one type, met as a ternary's arms are ([none, some(1)] is an option<number>[]; [1, "a"] is type-list-item).
xs.concat(ys), xs.slice(start, end?), xs.includes(x) and
xs.indexOf(x) are the web's array methods: [...xs, x] is
xs.concat([x]), includes finds a string, number or bool (by
SameValueZero, as the web does) and indexOf says where (by ===: NaN is
never found, -1 for none). Over text, s.indexOf(t) is a position in
UTF-16 code units, and s.split(", ") cuts text into a string[]
(recipient chips). A list the
screen keeps for the session — a selection, open or collapsed ids, per-row
offsets — is state built this way; a list the app keeps across launches, or
a server owns, belongs to the data module, and so do grouping, aggregates
and a stored order (a view orders what it holds with sortBy):
contract
state collapsed = []
action toggle(id: string)
collapsed = collapsed.includes(id) ? collapsed.filter(c => c != id) : collapsed.concat([id])
•
none and [] need an inferable element type. A state initialized by either
usually gets that information from later assignments; a typed argument or
the other conditional/match arm can also supply it, and a state may declare
it: state picked: option<Item> = none, state ids: string[] = [].
•
An option directly inside an option is refused (type-option-option):
option<option<T>> written, some(none), first or at of a
option<T>[], a mutation as shape option<T>. The web erases some,
so some(none) would be none there; hold the inner option in a record
field. A type nests at most 64 deep, through shapes, lists and options
(type-too-deep).
•
One evaluation (an action body, a derive, a binding, a key, an argument)
takes at most 65,536 list steps (each map/filter body run, each item
join prints or concat/slice/split keep, each item includes or
indexOf scans), builds strings of at most 64 MiB of UTF-8, and values of at
most 2²⁴ values and 64 MiB of string bytes. Every target refuses the same
step with the same reason: an action is refused with nothing changed; a prop
or style binding's row is unset, with one journal line naming its site and
the trap until it evaluates to a value again, and the app goes on; an if,
match or for subject, a key, a row's state initializer, a surface
argument or a virtualized list's own options stops the runner (LLP 1090,
LLP 1017.003 D3). Every build keeps Trap(Kind { pc: N }) verbatim, then
names the evaluation and bound in words: a derive or action's name, a resource
argument, a state initializer, or the view and plan site with its event
argument, subject, key, initializer, surface argument or list option. The JS
target names the site alone. Arguments count from 1. A binding already names
its site and row, so it adds only the bound. An inlined child derive or fn
names its reader; the pc is local to that code body, not a source location.
•
A state's initializer runs before any resource answers and before any derive:
it reads props, injects and the states declared above it, nothing else
(type-initializer-scope). Derive a value from a resource instead, or keep
per-row state in a component used inside for.
•
Shape(field=value, …) constructs every field exactly once.
Shape(base, field=value, …) copies a base of the same shape and replaces fields.
The one positional base comes first. Compiler-owned shapes are not constructible.
•
Use field access, arithmetic, comparisons, boolean operators, ternaries, and
exhaustive option matches. There is no truthiness or optional chaining.
•
Inline match is match x { case some(v) => a, case none => b }; the comma is
required and the some arm comes first. The block statement/view form has
separate indented case arms.
•
xs.map((x, i) => expr) and xs.filter(x => bool) return values, not nodes.
xs.join(separator) accepts primitive items. first(xs) and xs.at(i)
return options; at supports negative indices.
•
Two strings compare with <, <=, >, >= in UTF-16 code-unit order, as on
the web (end > start for "HH:MM" times). s.slice(0, -1),
s.replaceAll(find, with) and s.toLowerCase() are the web's string methods.
•
Numbers have floor, ceil, round (JavaScript's Math.round: round(-2.5) is
-2), min, max, %, formatNumber ("compact" is 1.2K, "decimal" 1,234.5,
"percent" 26%, "currency", "USD" $1,481.47), toFixed and formatDecimal. A
field's text is a number through match parseNumber(s) { case some(n) => …, case none => … }: a decimal numeral, trimmed, or none ("12px", "").
•
Money is a count of cents printed with formatDecimal(cents, 2), which is
exact (1234 is "12.34", -5 is "-0.05"). A price held as dollars
becomes cents with round(price * 100), which is right for a price of at
most two decimals under a trillion (19.99 is 1999, though 19.99 * 100
is 1998.9999999999998); past about 3.5e13 the double cannot hold the
cents, and a half cent such as 1.005 has no exact binary value and
becomes 100, so keep money in cents from the source when amounts can
have more places (tax, a split bill). formatDecimal of a number that is
not an integer prints "", so round first. x.toFixed(2) is the web's
x.toFixed(2), for a measured number (km.toFixed(1)): it rounds the
binary value too ((1.005).toFixed(2) is "1.00") and sums of dollars drift
(0.1 + 0.2), which is why money is counted in cents. Both take the digits as a whole-number literal (toFixed 0–100,
formatDecimal 0–20), never a variable, and print "" for NaN or
Infinity (JavaScript's toFixed prints "NaN").
contract
component Cart
state cents = 1999
state km = 12.34
view
column
text `Total $${formatDecimal(cents, 2)}` testId="total"
text `${km.toFixed(1)} km` testId="distance"
•
Dates: formatDate(ms, offset, "iso") is YYYY-MM-DD, and calendarDiff(from, to, "years") (or "months") is the whole periods between two such dates as an
option<number>, counted as an age is (a Feb 29 birthday has its year on Mar 1).
formatDate(due, 0, "medium") labels a picked YYYY-MM-DD day directly;
a key keeps its calendar day at every valid offset (dates recipe).
formatDay(then, now, offset, "day") names a day from now (Today, Yesterday, else
the date; "day-time" adds the time, "list" is a list row's, as Mail's, and
"section" a chat's day separator: a weekday within the week, else Thu, Oct 15).
•
formatTime, formatDate, formatDay and formatNumber follow the strings table
the app shows: with strings/de.json shown they print 26.09.2026, 13:02,
1.234,5 and Heute, and setLocale moves them with the text; the examples above
are en-US, which an app with no tables or only English ones prints. Do not write a
formatter of your own per language, and do not key one on resolvedLocale. A
table's region is its formats' (en-GB.json, which may be {}, prints 26 Sep 2026); dates are Gregorian everywhere
(formatting by locale).
•
There is no general list append: add an item to
resource-backed data in its source and answer the updated list (a mutation that
refreshes the list's resource, or its own answer).
•
The web's string and array methods are written as methods, with their names
and meanings: s.trim(), s.includes(q), xs.filter(x => …), n.toFixed(2),
xs.length. The free spelling (trim(s)) is refused with the edit
(syntax-method-form), and so is a method Contract lacks (xs.reduce(…),
syntax-method-call). The rest of the roster is functions: first(xs),
round(n), parseNumber(s), formatNumber(…). There are no object
literals, spreads, general lambdas, array indexing,
assignment expressions, or JavaScript built-ins by implication.
•
fn label(done: bool): string = done ? "Done" : "Open" is a function: parameters
and the return type are explicit, after : (not ->). Its body is one expression over
its parameters and standard calls (including performanceNow()), without component-state
capture or recursion. Pass an app value in; do not invent an ambient reference.
A fn named like a standard function (fn indexOf) shadows it in every
free call of the app, so a standard function added later never breaks an
app that had the name first; an action or a host command keeps its own rule.
A method call (xs.indexOf(x)) is always the built-in: calling one whose name
the file also declares is refused (syntax-method-shadowed).
•
Named arguments belong to component uses, record constructors,
t("key", placeholder=value), empty(field=value), canvas surface= bindings,
the commands share(…), scrollIntoView(…), playSound(…) and
stopSounds(…), and a native module's sources and sends
(showNotification(…)). Every other function takes positional arguments.
For the full roster and special calls, see
standard functions and intrinsics.
For record behavior in a callback, use records
and the record tests.
Is this helpful
Last updated November 30, 2026