Skip to content

Language overview ​

ChadScript compiles a subset of TypeScript. The subset is not a dialect: every accepted program is valid TypeScript with the same meaning, and it runs unchanged under Node. What changes is the set of programs the compiler agrees to build.

The rules in one screen ​

  1. It must typecheck at maximum strictness. strict, noUncheckedIndexedAccess, exactOptionalPropertyTypes, noImplicitOverride and noPropertyAccessFromIndexSignature are always on, with zero diagnostics allowed. Array reads are T | undefined, so you narrow or default them (xs[i] ?? 0).
  2. Every construct must be one the compiler supports. The accepted subset lists them, straight from the compiler's own tables. Anything else is rejected with a code and a rewrite.
  3. Objects keep the shape they were created with. No adding or deleting properties, no prototype edits. Optional fields (x?: T) are how you model "maybe present".
  4. Types decide the machine layout. number, string and boolean are stored directly. A union of different kinds (number | string) carries a small type tag, and you narrow it (typeof x === "number") before most operations.
  5. Strings are ASCII for now. A non-ASCII string literal is rejected at compile time, and non-ASCII text arriving at run time (a command-line argument, a file read as text, socket data) stops the program with an error rather than being measured or indexed differently from Node. Within ASCII, every string operation (s[i], for...of, <, charCodeAt) is exact.

Topics ​

Every example on these pages is a file in docs/examples/. The test suite compiles each one and checks that the binary's output matches Node's at -O0 and -O2, and that the output shown on the page is what Node prints.

TopicCovers
Modules and importsnamed, default, namespace and type-only imports; re-exports; packages
Classes and interfacesinheritance, super, override, instanceof, interface dispatch
Unions and narrowingtypeof, ===, Array.isArray, discriminated unions, ??
Genericsgeneric functions and classes, constraints, erasure
Closurescaptured mutable variables, per-iteration bindings, higher-order functions
Map and Setcounting, iteration order, spreading keys, new Map from pairs
async / awaitNode's microtask ordering, Promise.all, new Promise, timers
Errorsthrow, try/catch/finally, Error classes, uncaught errors
JSONtyped JSON.parse with shape checking, JSON.stringify, cycles
node:fs and node:pathsync and promise file APIs, path helpers, process.argv
console.logutil.inspect formatting, format directives, String() and templates

Not in the subset ​

Permanently out, because they need a JavaScript engine rather than a compiler: any, eval and new Function, prototype mutation, adding or deleting properties at run time, Proxy, CommonJS, and packages that ship only JavaScript. Programs that need them should run on Node.

Not yet, planned: regular expressions, Date instances, optional and default parameters, getters and setters, toFixed, .then() on promises, classes that extend Error, generics instantiated with arrays or functions (wrap them in an object), optional chains longer than one ?., and Map/Set keyed by a union. Each is rejected today with a specific code; see the limitations and the roadmap.

Next: Modules and imports.