Tsonic GitHub
Edit on GitHub

Basic Examples

Default CLR surface

Setup:

tsonic init
tsonic run

Code:

import { Console } from "@tsonic/dotnet/System.js";

export function main(): void {
  Console.WriteLine("Hello from CLR");
}

JS surface

Setup:

tsonic init --surface @tsonic/js
tsonic run

Code:

export function main(): void {
  const name = "  tsonic  ".trim().toUpperCase();
  console.log(name);
}

JS surface + Node package

Setup:

tsonic init --surface @tsonic/js
tsonic add npm @tsonic/nodejs
tsonic run

Code:

import * as fs from "node:fs";
import * as path from "node:path";

export function main(): void {
  const file = path.join("src", "App.ts");
  console.log(fs.existsSync(file));
}

Source package consumption

This is the current first-party package model generalized to your own packages:

import { clamp } from "@acme/math";

export function main(): void {
  console.log(clamp(10, 0, 5).toString());
}

That works when @acme/math is a Tsonic source package with a compatible tsonic.package.json manifest.