ChadScriptShip TypeScript as a tiny native program.
ChadScript compiles ordinary TypeScript into one small executable that starts instantly. If it compiles, it prints exactly what Node would. If it can't promise that, it tells you why and how to fix it.
ChadScript knows the shape of every object when the program is compiled, which is a big part of why the binary is small and fast. Code that would change an object's shape later is stopped before it ships, with a message that points at the line and says how to fix it:
ts
interface User { name: string; email?: string;}const user: User = { name: "ada" };user.email = "ada@example.com";console.log(user);
text
$ bin/chad check rejected-shape.tserror[CS1235]: assigning `.email` can add a property to an object created without it (the object literal at rejected-shape.ts:8); objects cannot gain properties --> rejected-shape.ts:9:1 help: create every such object with the property: declare it `email?: T | undefined` and initialize it (`email: undefined`), or use a class that declares `email`1 error(s)
Declare the property up front and it compiles, and prints what Node prints:
ts
interface User { name: string; email?: string | undefined;}const user: User = { name: "ada", email: undefined };user.email = "ada@example.com";console.log(user);
text
{ name: 'ada', email: 'ada@example.com' }
A program either behaves exactly like Node or does not compile. There is no third outcome.
One self-contained executable, about 130 KB for a small program. It starts in about a millisecond: no engine to boot and no warm-up. Copy it to a machine without Node and run it.
Same results as Node
More than 380 test programs are run with Node and as native binaries on every change, and any difference in output fails the build. Fuzzers add over 100 generated programs to every run.
The TypeScript you already write
Modules and imports, classes, interfaces, unions, generics, closures, Map and Set, async/await, typed JSON.parse, node:fs and node:path.
ChadScript is an alpha, not released yet, and developed in the open. If you find a program that compiles but prints something different from Node, that is the most important kind of bug: please open an issue. Curious how it works? Read how it works or see the roadmap.