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

Compilation modes

Programs can combine native code and an optional embedded JavaScript engine. Unsupported operations produce compilation diagnostics.

Tier 1

Compiled statically

Supported TypeScript and JavaScript operations compile to native code. Static executables run without Node.js or a JavaScript engine.

Tier 2

Runs dynamically

Enable --dynamic to run npm packages and supported any-typed code in an embedded JavaScript engine. Values converted to static types are checked at runtime.

Tier 3

Rejected at compile time

Unsupported operations produce a diagnostic with an error code, a source location, and a rewrite hint where available.

Check compilation support

Use scriptc coverage to analyze a program before building it. The report identifies operations that compile statically, require the embedded engine, or remain unsupported.

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 — this program has no dynamic remainder.

TypeScript type checking

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

Native executables

Build a program into an executable for a supported target. JavaScript dependencies used with --dynamic are embedded at build time.

Compilation coverage

Coverage reports show static and dynamic statement counts and list compilation blockers for the program being analyzed.

Differentially tested

The test corpus compares program output and exit codes under Node.js and compiled execution. A sanitizer lane checks 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.