A native ahead-of-time (AOT) and JIT compiler for TypeScript, built on LLVM/MLIR.
It compiles .ts files directly to native executables, WebAssembly, or runs them
on the fly via a built-in JIT — no Node.js or JavaScript runtime required.
Implemented
try/catchexception handling in the JIT on Windows (x64 SEH unwinding via a custom LLJIT runtime)Migrared to LLVM 22.1.8
Migrated to Visual Studio 2026 (Windows build chain)
JavaScript Built-in objects library [Default Library repo]
Visual Studio Code project
tslang --new Test1- CMake project (mixed C++/TypeScript,
TSLANGregistered as a first-class CMake language)
tslang --cmake Test1Generates a ready-to-build project (CMakeLists.txt, CMakePresets.json, main.cpp, sample .ts sources and the cmake/ TSLANG language modules). Build it with:
cd Test1
cmake --preset default && cmake --build --preset default- Strict null checks
letsn: string|null=null;// Oklets: string=null;// error- Improved
Template Literal Types
typeColor="red"|"green"|"blue";typeHexColor<TextendsColor>= `#${string}`;- Public, private, and protected modifiers
classPoint{privatex: number;
#y: number;}constp=newPoint();p.x// access errorp.#y // error- Class from Tuple
classPoint{x: number;y: number;}classLine{constructor(publicstart: Point,publicend: Point){}}constl=newLine({x: 0,y: 1},{x: 1.0,y: 2.0});- Compile-time
ifs
functionisArray<Textendsunknown[]>(value: T): value is T{returntrue;}functiongen<T>(t: T){if(isArray(t)){returnt.length.toString();}return"int";}constv1=gen<i32>(23);// result: intconstv2=gen<string[]>([]);// result: 0Migrated to LLVM 19.1.3
Improved
generating debug information— more info here: Wiki:How-To
tslang --di --opt_level=0 --emit=exe example.ts- Migrating to LLVM 22.1.8
- Shared libraries
- JavaScript Built-in classes library
See the release page for a recorded demo
Open the WASM example on Compiler Explorer
Want to chat with other members of the TypeScriptCompiler community?
- GitHub Discussions (preferred)
(legacy)
abstractclassDepartment{constructor(publicname: string){}printName(): void{print("Department name: "+this.name);}abstractprintMeeting(): void;// must be implemented in derived classes}classAccountingDepartmentextendsDepartment{constructor(){super("Accounting and Auditing");// constructors in derived classes must call super()}printMeeting(): void{print("The Accounting Department meets each Monday at 10am.");}generateReports(): void{print("Generating accounting reports...");}}functionmain(){letdepartment: Department;// ok to create a reference to an abstract typedepartment=newAccountingDepartment();// ok to create and assign a non-abstract subclassdepartment.printName();department.printMeeting();//department.generateReports(); // error: department is not of type AccountingDepartment, cannot access generateReports}Run
tslang --emit=jit --opt --shared-libs=TypeScriptRuntime.dll example.tsResult
Department name: Accounting and Auditing
The Accounting Department meets each Monday at 10am.
File hello.ts
functionmain(){print("Hello World!");}Build
tslang hello.tsResult
Hello World!
JIT-compiled TypeScript can be debugged at source level with GDB — breakpoints on .ts lines,
stepping, and backtraces all work. The JIT registers every compiled object with the debugger via
the standard GDB JIT interface,
so an attached GDB picks up the DWARF debug info at runtime.
Two things are required:
- pass
--diso the compiler emits debug information; - run without
--opt(JIT debug registration is only enabled when optimizations are off).
gdb --args tslang --di hello.ts
(gdb) break hello.ts:2
Make breakpoint pending on future shared library load? (y or [n]) y
(gdb) runThe breakpoint stays pending until the JIT compiles and registers your code, then binds and stops with full source context:
Thread 1 "tslang" hit Breakpoint 1, main () at hello.ts:2
2 print("Hello World!");
From there the usual GDB commands work on the JIT'd frames: next, step, info locals, bt.
Notes:
- The
(No debugging symbols found in tslang)warning at startup refers to the compiler binary itself and is harmless — the debug info for your code arrives when the JIT registers it. - The
debugger;TypeScript statement is also supported: it compiles to a debug trap instruction, so execution stops exactly there when a debugger is attached. Without a debugger attached it terminates the process withSIGTRAP, so remove it when you are done. - For LLDB, enable its JIT loader first:
settings set plugin.jit-loader.gdb enable.
Make sure you have download
tslangfrom releases first.
The compile process may use a few environment variables so the linker can find the
runtime libraries, then invoke tslang with --emit=exe. Edit the paths to match your
checkout — the C:\dev\... / ~/dev/... values are only examples.
| Variable | Points to |
|---|---|
GC_LIB_PATH | Boehm GC library (the garbage collector) |
LLVM_LIB_PATH | LLVM/MLIR libraries |
TSLANG_LIB_PATH | TSLANG runtime library |
DEFAULT_LIB_PATH | Default library |
Build
tslang --emit=exe hello.tsRun
hello.exe
Result
Hello World!
Build
./tslang --emit=exe hello.ts --relocation-model=picRun
./hello
Result
Hello World!
Build
tslang.exe --emit=exe --nogc -mtriple=wasm32-unknown-unknown hello.tsRun run.html
Click to expand the full run.html WebAssembly loader
<!DOCTYPE html><html><head></head><body><scripttype="module">letbuffer;letbuffer32;letbuffer64;letbufferF64;letheap;letheap_base,heap_end,stack_low,stack_high;constallocated=[];constallocatedSize=(addr)=>{returnallocated[""+addr];};constsetAllocatedSize=(addr,newSize)=>{allocated[""+addr]=newSize;};constexpand=(addr,newSize)=>{constaligned_newSize=newSize+(4-(newSize%4))constend=addr+allocatedSize(addr);constnewEnd=addr+aligned_newSize;for(constallocatedAddrinallocated){constbeginAllocatedAddr=parseInt(allocatedAddr);constendAllocatedAddr=beginAllocatedAddr+allocated[allocatedAddr];if(beginAllocatedAddr!=addr&&addr<endAllocatedAddr&&newEnd>beginAllocatedAddr){returnfalse;}}setAllocatedSize(addr,aligned_newSize);if(addr+aligned_newSize>heap)heap=addr+aligned_newSize;returntrue;};constendOf=(addr)=>{while(buffer[addr]!=0){addr++;if(addr>heap_end)throw"out of memory boundary";};returnaddr;};conststrOf=(addr)=>String.fromCharCode(...buffer.slice(addr,endOf(addr)));constcopyStr=(dst,src)=>{while(buffer[src]!=0)buffer[dst++]=buffer[src++];buffer[dst]=0;returndst;};constncopy=(dst,src,count)=>{while(count-->0)buffer[dst++]=buffer[src++];returndst;};constappend=(dst,src)=>copyStr(endOf(dst),src);constcmp=(addrL,addrR)=>{while(buffer[addrL]!=0){if(buffer[addrL]!=buffer[addrR])break;addrL++;addrR++;}returnbuffer[addrL]-buffer[addrR];};constprn=(str,addr)=>{for(leti=0;i<str.length;i++)buffer[addr++]=str.charCodeAt(i);buffer[addr]=0;returnaddr;};constclear=(addr,size,val)=>{for(leti=0;i<size;i++)buffer[addr++]=val;};constaligned_alloc=(size)=>{constaligned_size=size+(4-(size%4));if((heap+aligned_size)>heap_end)throw"out of memory";setAllocatedSize(heap,aligned_size);constheapCurrent=heap;heap+=aligned_size;returnheapCurrent;};constfree=(addr)=>deleteallocated[""+addr];constrealloc=(addr,size)=>{if(!expand(addr,size)){constnewAddr=aligned_alloc(size);ncopy(newAddr,addr,allocatedSize(addr));free(addr);returnnewAddr;}returnaddr;}constenvObj={memory: newWebAssembly.Memory({initial: 256}),table: newWebAssembly.Table({initial: 0,element: 'anyfunc',}),fmod: (arg1,arg2)=>arg1%arg2,sqrt: (arg1)=>Math.sqrt(arg1),floor: (arg1)=>Math.floor(arg1),pow: (arg1,arg2)=>Math.pow(arg1,arg2),fabs: (arg1)=>Math.abs(arg1),_assert: (msg,file,line)=>console.assert(false,strOf(msg),"| file:",strOf(file),"| line:",line," DBG:",path),puts: (arg)=>output+=strOf(arg)+'\n',strcpy: copyStr,strcat: append,strcmp: cmp,strlen: (addr)=>endOf(addr)-addr,malloc: aligned_alloc,realloc: realloc,free: free,memset: (addr,size,val)=>clear(addr,size,val),atoi: (addr,rdx)=>parseInt(strOf(addr),rdx),atof: (addr)=>parseFloat(strOf(addr)),sprintf_s: (addr,sizeOfBuffer,format, ...args)=>{constformatStr=strOf(format);switch(formatStr){case"%d": prn(buffer32[args[0]>>2].toString(),addr);break;case"%g": prn(bufferF64[args[0]>>3].toString(),addr);break;case"%llu": prn(buffer64[args[0]>>3].toString(),addr);break;default: throw"not implemented";}return0;},}constconfig={env: envObj,};WebAssembly.instantiateStreaming(fetch("./hello.wasm"),config).then(results=>{const{ main, __wasm_call_ctors, __heap_base, __heap_end, __stack_low, __stack_high }=results.instance.exports;buffer=newUint8Array(results.instance.exports.memory.buffer);buffer32=newUint32Array(results.instance.exports.memory.buffer);buffer64=newBigUint64Array(results.instance.exports.memory.buffer);bufferF64=newFloat64Array(results.instance.exports.memory.buffer);heap=heap_base=__heap_base,heap_end=__heap_end,stack_low=__stack_low,stack_high=__stack_high;try{if(__wasm_call_ctors)__wasm_call_ctors();main();}catch(e){console.error(e);}});</script></body></html>Visual Studio 2026- ~50 GB of free disk space (LLVM/MLIR build dominates this)
The hardcoded
C:\dev\...paths in the scripts below are examples — adjust them to your checkout location.
First, precompile dependencies
cd TypeScriptCompiler
prepare_3rdParty.batTo build TSLANG binaries:
cd TypeScriptCompiler\tslang
config_tslang_release.bat
build_tslang_release.batgccorclangcmakeninja-build- ~50 GB of free disk space (LLVM/MLIR build dominates this)
- sudo apt-get install
libtinfo-dev
First, precompile dependencies
chmod +x *.sh
cd~/TypeScriptCompiler
./prepare_3rdParty.shTo build TSLANG binaries:
cd~/TypeScriptCompiler/tslang
chmod +x *.sh
./config_tslang_release.sh
./build_tslang_release.shThis project is licensed under the MIT License — see the LICENSE file for details.
Issues and pull requests are welcome. See the Wiki for documentation, build notes, and how-to guides.


