zigtsc
A compiler written in Zig that transpiles a strict subset of TypeScript directly to idiomatic C. No Wasm intermediate. No runtime. Just clean C output.
TypeScript syntax→ C outputWritten in Zig
git clone https://github.com/nathanjmorton/zigtsc && cd zigtsc && zig build -Doptimize=ReleaseFastclick to copy
Requires Zig 0.16.0 · GitHub · Docs
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
Direct TS → C
No Wasm intermediate like Porffor. Generates idiomatic, readable C you can inspect and modify.
Written in Zig
Fast compiler with zero runtime dependencies. Single binary, cross-platform.
Type-driven codegen
number → double, boolean → bool, string → const char*, interface → typedef struct.
console.log → printf
Format strings inferred from types. Strings use %s, numbers use %g, booleans use %d.
Explicit subset
No classes, closures, async, generics, or eval. Designed constraints for clean C mapping.
Pairs with zigc
Output .c files can be built with zigc, zig cc, gcc, or clang. Full C toolchain compatibility.
Quick start
git clone https://github.com/nathanjmorton/zigtsccd zigtsc && zig build -Doptimize=ReleaseFast./zig-out/bin/zigtsc examples/fib.ts fib.ccc -o fib fib.c && ./fib