zigtsc

A compiler written in Zig that transpiles a strict subset of TypeScript to C, C++, and JavaScript. Classes, interfaces, type-checked. Three targets from one source.

TypeScript syntax→ C / C++ / JSGo-style classesWritten in Zig
brew install nathanjmorton/zigtsc/zigtsc
click to copy

or

curl -fsSL https://raw.githubusercontent.com/nathanjmorton/zigtsc/main/install.sh | bash
click to copy

macOS · Linux · arm64 / x86_64 · GitHub · Docs · zigc

TypeScript in, C out

fib.ts
function fib(n: number): number {
    if (n <= 1) {
        return n;
    }
    return fib(n - 1) + fib(n - 2);
}

const result: number = fib(10);
console.log(result);
fib.c (generated)
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>

double fib(double n);

double fib(double n) {
    if ((n <= 1)) {
        return n;
    }
    return (fib((n - 1)) + fib((n - 2)));
}

int main(void) {
    const double result = fib(10);
    printf("%g\n", result);
    return 0;
}

Features

Three targets

One source file → C, C++, or JavaScript. Use -target c, -target cpp, or -target js.

Go-style classes

Classes with constructors, methods, and this. No inheritance. C++ target emits .h/.cpp pairs per class.

Written in Zig

Fast compiler with zero runtime dependencies. Single binary, cross-platform.

Type-driven codegen

number → double, boolean → bool, string → const char*, interface → struct, class → C++ class.

console.log → printf

Format strings inferred from types in C/C++. Stays as console.log in JS output.

Built for zigc

Transpile with zigtsc, compile with zigc. zigc build handles C and C++ output. Full native + WASM pipeline.

Quick start

zigtsc init demo && \
zigtsc transpile demo/src/main.ts && \
zigtsc compile demo/src/zigtscout && \
zigtsc run demo/zig-out/bin/main && zigtsc run demo/zig-out/wasm/main.wasm
click to copy

Read the full docs →