Tsonic GitHub

Tsonic User Guide

Tsonic compiles TypeScript to native executables via C# and .NET NativeAOT.

Table of Contents

Getting Started

  1. Getting Started - Installation and first project
  2. CLI Reference - Commands and options
  3. Configuration - tsonic.json reference

Language

  1. Language Guide - Supported features
  2. Type System - Type mappings
  3. Numeric Types - Integer types and narrowing
  4. Generators - Sync, async, and bidirectional generators
  5. Callbacks - Action and Func patterns
  6. Async Patterns - Async/await and for-await
  7. .NET Interop - Using .NET BCL
  8. CLR Bindings & Workspaces - Where bindings live; multi-project repos
  9. Language Intrinsics - stackalloc, trycast, thisarg, etc.
  10. JavaScript Runtime - Optional JS-style APIs via @tsonic/js

Build

  1. Build Output - Pipeline and output
  2. Diagnostics - Error codes reference

Reference

  1. Examples - Code examples
  2. Troubleshooting - Common issues
  3. Limitations - What Tsonic can’t do (yet)

Overview

What is Tsonic?

Tsonic is a compiler that transforms TypeScript source code into native executables:

TypeScript → IR → C# → NativeAOT → Native Binary

Why Tsonic?

  • Native Performance: Compile to fast, single-file executables
  • TypeScript Familiarity: Use the language you know
  • Full .NET Access: Call any .NET library
  • No Runtime Required: Self-contained binaries

Direct .NET Access

  • C# semantics for all types
  • Import from System.*, System.IO, System.Linq, etc.
  • Full BCL access
  • Native arrays (T[]) and .NET collections

Prerequisites

  • Node.js 22+: For the CLI and type packages
  • .NET 10 SDK: For compilation
  • npm: For package management

Verify installation:

node --version   # v22.0.0 or higher
dotnet --version # 10.0.x

Installation

npm install -g tsonic
tsonic --version

Your First Program

# Create project
mkdir hello && cd hello
tsonic project init

# Build
npm run build

# Run
./out/app

Output:

Hello from Tsonic!
Doubled: 2, 4, 6, 8, 10