Skip to main content
Ant runs TypeScript files the same way it runs JavaScript files. You point it at a .ts or .tsx file and it executes immediately — no tsc, no build step, no configuration file required. Type annotations, interfaces, generics, and type aliases are stripped at load time using Ant’s built-in OXC type-stripper, leaving only the JavaScript for the engine to execute.

Running a TypeScript file

ant hello.ts
That’s the entire workflow. Ant detects the .ts extension, strips the types, and runs the result. You can use any TypeScript syntax that OXC supports for type stripping.

Type annotations and interfaces

interface User {
  name: string;
  age: number;
}

function greet(user: User): string {
  return `Hello, ${user.name}!`;
}

const alice: User = { name: "Alice", age: 30 };
console.log(greet(alice));
Save this as greet.ts and run it with ant greet.ts. The User interface and all type annotations are stripped before execution — none of them reach the engine.

Generics and type aliases

type Result<T> = { ok: true; value: T } | { ok: false; error: string };

function divide(a: number, b: number): Result<number> {
  if (b === 0) return { ok: false, error: "division by zero" };
  return { ok: true, value: a / b };
}

const result = divide(10, 2);
if (result.ok) console.log(result.value);

Real-world example: Hono HTTP server

The following file is taken from the Hono example in Ant’s own examples directory. It is a .ts file that Ant runs directly, with no compilation step.
import { Hono } from 'hono';
import { logger } from 'hono/logger';

const app = new Hono();

app.use(logger());
app.get('/', c => c.text(`hello hono!!\n\n🐜 ${Ant.version}\n`));

console.log('started on http://localhost:3000');

export default app;
Run it with:
ant add hono
ant src/index.ts
Exporting a default Hono app causes Ant to start an HTTP server automatically on port 3000.

FFI with TypeScript

TypeScript also works with Ant’s native FFI bindings. This example from examples/ffi/basic/printf.ts uses an interface to type a native C library:
import { dlopen, suffix, FFIType } from 'ant:ffi';

let libcName: string;
if (process.platform === 'darwin') {
  libcName = `libSystem.${suffix}`;
} else if (process.platform === 'linux') {
  libcName = `libc.${suffix}`;
} else if (process.platform === 'win32') {
  libcName = `msvcrt.${suffix}`;
} else throw new Error(`Unsupported platform: ${process.platform}`);

interface libC {
  putchar(c: number): number;
  printf(format: string, ...args: unknown[]): number;
}

const libc = dlopen<libC>(libcName);

libc.define('putchar', { args: [FFIType.int], returns: FFIType.int });
libc.define('printf', { args: [FFIType.string, FFIType.spread], returns: FFIType.int });

libc.putchar(65); // 'A'
libc.printf('Hello FFI! I see %d\n', 42);
Run it with ant printf.ts. The generic dlopen<libC>() call and the interface libC block are stripped at load time; only the runtime JavaScript reaches the engine.

How type stripping works

Ant uses the OXC type-stripper to remove TypeScript-specific syntax before execution. You can confirm this at runtime:
console.log(process.features.typescript); // "transform"
The value "transform" indicates that Ant strips types rather than performing a full TypeScript compilation.
Ant does not perform type checking. Type errors are silently ignored at runtime — only JavaScript logic errors will surface. Use tsc --noEmit separately if you want to type-check your code before running it.

tsconfig.json

Ant looks for a tsconfig.json in the project directory if one is present, but does not require it. If no tsconfig.json exists, Ant applies reasonable defaults. Path aliases defined in tsconfig.json paths are not resolved by Ant’s type-stripper — use a bundler or explicit import paths instead.
You can run TypeScript files in watch mode the same way as JavaScript: ant -w server.ts. See Watch mode for details.