The language
xisto is a strict subset of TypeScript. It reads TypeScript syntax and gives it static semantics: every value has a type the compiler knows, and that type decides the machine code. What it asks in exchange for native speed is a small set of rules. This section states them, with the reason for each.
Principles
- TypeScript syntax, static semantics. No new syntax. The type
intis the one addition; Node strips type annotations, so on Node anintis simply anumber. - Valid xisto is valid TypeScript. A program that compiles with xisto runs on Node with the same output. The
repository's test suite checks this for every program in
tests/ok/: Node is the oracle. - Nothing implicit. Conversions that JavaScript does silently (
1 == "1",if (n)on anumber) are either refused or compiled with a warning that says what happens. - Good errors. Every diagnostic has a stable code, the place, the rule and a fix:
x.ts:3:16: error[XS8082]: array index must be int, but this is number
3 | console.log(xs[k]);
| ^
help: declare the index as int, or convert it with Math.trunc(x)
- Divergences are deliberate. Where xisto behaves differently from Node, it is on purpose and listed in Divergences from TypeScript.
What changes for you
Most typed TypeScript compiles as written. The rules you meet first:
| Rule | Page |
|---|---|
int and number are different types | Numbers |
null is the only empty value; undefined reads as null | null and absent values |
== never converts; numbers are not conditions | Equality and truthiness |
any works, but takes a slower, checked path | any |
| generics are compiled once per type | Classes, interfaces and generics |
await f() is a direct call | Functions and async |
Map of this section
- Numbers:
int,number, literals, overflow, bitwise,bigint. - null and absent values: optional fields,
?.,??, narrowing. - Equality and truthiness:
==, conditions,&&and||. - any: the checked dynamic path and its cost.
- Classes, interfaces and generics: dispatch, adapters, unions, tuples.
- Functions and async: closures, promises, timers.
- Generators:
function*andfor…of. - Modules: imports, barrels,
xisto:andnode:, packages. - Errors:
throw,try, stack traces. - Decorators: static reflection and method decorators.
- Divergences from TypeScript: the full table.
- Warnings: rule warnings and
--deny-warnings. - Known limitations: what is not supported yet.
For the performance side of these rules, see Best practices.