macOS · Linux · Windows

TypeScript-to-Native Compiler

Compile TypeScript and JavaScript to native executables and WebAssembly. Check compilation support with coverage reports.

fib.ts — compiled with scriptc
$ cat fib.ts
function fib(n: number): number {
  return n < 2 ? n : fib(n - 1) + fib(n - 2);
}
console.log(fib(30));

$ scriptc run fib.ts
832040

$ scriptc build fib.ts -o fib >/dev/null
$ ./fib
832040

From TypeScript to a native binary

Write the same TypeScript you run on Node.js. scriptc turns it into machine code in three steps.

Step 1

Type-check

The TypeScript compiler checks your program against your tsconfig.json. scriptc uses the checked types to choose a native representation for every value.

Step 2

Compile

LLVM generates machine code for your program and the npm packages it imports. Anything unsupported is reported with a code, a location, and a hint.

Step 3

Ship

The result is one executable for macOS, Linux, or Windows, or a WebAssembly module. It runs without Node.js installed.

How it works →

Check compilation support

Run scriptc coverage on an existing program to see how much of it compiles before you build. The report explains anything unsupported and suggests a fix.

Reading coverage reports →
$ cat hello.ts
const who: string = process.argv.length > 2 ? process.argv[2] : "world";
console.log(`hello, ${who}`);

$ scriptc coverage hello.ts

  statements analyzed   2
  compile statically    2  (100%)

  fully static — all analyzed statements compile to native code.

TypeScript type checking

The compiler uses TypeScript's type information and narrowing rules to select native representations and identify unsupported operations.

npm packages included

Packages your program imports compile into the executable, which doesn't read node_modules at runtime.

Cross-compilation

Build for Linux, Windows, and WebAssembly from one machine, and build static libraries for iOS and Android apps.

Tested against Node.js

The test suite runs each test program under Node.js and as a compiled executable and compares their output and exit codes. AddressSanitizer builds check for memory errors.

Compile your first binary

Install the CLI, create a TypeScript file, and build an executable. The quickstart covers platform requirements and npm dependencies.