The Velt Reference
This is the precise description of the Velt language: what the compiler accepts, what it rejects, and what the compiled program does. For a guided introduction, read the Book; for imported modules, the standard library.
Velt is TypeScript compiled to native code, with Rust-class performance, a multi-core runtime and no garbage collector. Three rules shape every decision:
- valid TypeScript runs as it does in Node;
- where JavaScript's behavior is a trap (comparing
1 == "1", a forgottenawait), the compiler stops and says what to write instead; - TypeScript is the starting point, not the limit: Velt adds its own opt-in features wherever
they make programs faster or safer (integer types, typed errors,
shared,extend).
Conventions
- This reference describes what the compiler does. Every code block marked as Velt is
compiled by the documentation tests, and the behavior is pinned by the end-to-end tests in
tests/golden/. - Planned marks a decided design that is not built yet. Planned code is never shown as working.
- Error messages are quoted verbatim, so you can search for them.
Contents
- Lexical structure — programs, comments, literals, keywords, operators
- Types — numbers, strings, equality,
null, literal types, unions, discriminated unions, intersection, branded and indexed access types, enums, objects, arrays, tuples, maps - Variables and conditions —
const/let, truthiness, module state - Functions and closures — parameters, generics, arrows, captures
- Classes, structs, interfaces and generics — members, inheritance, dispatch,
extend,Comparable - Control flow — loops,
for...of,switch - Errors — typed
throw/try/catch,throwsclauses, panics - Async and concurrency — promises,
spawn,shared,Mutex - Memory model — ownership, inferred mutation, exclusive access,
using - Modules and packages — imports, exports, specifiers
- Built-ins — what is in scope without an import
- Diagnostics — the format and wording of compiler errors
- TSX — JSX syntax, the provider, typing of elements and components, async components, how elements are compiled
- System functions —
declare system function: the C library, safely - Source generators —
declare generated function: bodies a library writes per type at compile time (experimental)
How Velt differs from TypeScript, item by item, is in Velt for TypeScript developers.
Planned changes at a glance
Decided direction that is not implemented yet. Each chapter says where it applies.
| Planned | Chapter |
|---|---|
weak references and a compile-time warning for reference cycles | Memory model |
No struct keyword: a class covers what a struct does (structs already behave as objects) | Classes |
extend: module scoping | Classes, Modules |
TSX: elements in the props of a component that takes ownership of them (children: JSX.Element); everything else in TSX works | TSX |