Skip to content
Language reference

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 forgotten await), 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#

  1. Lexical structure — programs, comments, literals, keywords, operators
  2. Types — numbers, strings, equality, null, literal types, unions, discriminated unions, intersection, branded and indexed access types, enums, objects, arrays, tuples, maps
  3. Variables and conditions — const/let, truthiness, module state
  4. Functions and closures — parameters, generics, arrows, captures
  5. Classes, structs, interfaces and generics — members, inheritance, dispatch, extend, Comparable
  6. Control flow — loops, for...of, switch
  7. Errors — typed throw/try/catch, throws clauses, panics
  8. Async and concurrency — promises, spawn, shared, Mutex
  9. Memory model — ownership, inferred mutation, exclusive access, using
  10. Modules and packages — imports, exports, specifiers
  11. Built-ins — what is in scope without an import
  12. Diagnostics — the format and wording of compiler errors
  13. TSX — JSX syntax, the provider, typing of elements and components, async components, how elements are compiled
  14. System functions — declare system function: the C library, safely
  15. 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.

PlannedChapter
weak references and a compile-time warning for reference cyclesMemory model
No struct keyword: a class covers what a struct does (structs already behave as objects)Classes
extend: module scopingClasses, Modules
TSX: elements in the props of a component that takes ownership of them (children: JSX.Element); everything else in TSX worksTSX

Edit this page on GitHub