Nish

Nish — Native Instruction Static Host — compiles a strict, static subset of TypeScript ahead of time to native code. You write .ts files with the syntax you already know; the compiler checks that every value has one fixed type and layout, turns the program into LLVM IR, and LLVM turns that into a small executable for x86_64, ARM64 or WebAssembly. There is no interpreter, no garbage collector and nothing to ship beside the binary.

Nish is pre-alpha. Do not use it in production. It is an early experiment, not a tool to build on yet: expect miscompilations, crashes, missing features and confusing diagnostics. Until 1.0 the language, the command-line flags and the output all change without notice, often between one minor release and the next. If you try it, pin an exact version and read the changelog before you upgrade.

Why Nish

The TypeScript you know

Arrow functions, classes, interfaces, discriminated unions, generics and modules, in .ts files your editor already understands.

One binary, nothing beside it

LLVM builds a small executable for x86_64, ARM64 or WebAssembly. No runtime to install, no interpreter, no JIT warming up.

No garbage collector

The compiler decides where every value lives and when its memory is reused, so nothing pauses the program to scan for garbage.

Errors you can act on

What only makes sense at run time — any, exceptions, prototypes — is a compile error with a stable code and a message saying what to write instead.

Checked by default

Integers have fixed widths, and arithmetic that overflows stops the program with a message rather than wrapping round.

A way back out

A Nish module is still TypeScript: the nish package runs it in Node or a browser, and a native build can be called from Node, WebAssembly or C.

A first look

const sumOfSquares = (limit: i32): i32 => {
  let total = 0;
  for (let i = 1; i <= limit; i++) {
    total = total + i * i;
  }
  return total;
};

export const main = (): i32 => {
  console.log(`1² + … + 10² = ${sumOfSquares(10)}`);
  return 0;
};

i32 is a 32-bit integer, export const main is where the program starts and its return value is the exit status, and total + i * i is checked: if it overflowed, the program would stop with a message rather than wrap round. Save it as squares.ts and nish run squares.ts prints 1² + … + 10² = 385.

Explore the docs

Every page

This guide teaches; it is not the definition of the language. That is the language reference, and each page here links the section of it that governs what the page describes. Where the two disagree, the reference is right and the guide has a bug.