TypeScript Macros, Powered by Rust

Compile-time code generation with a Rust-like derive system. Eliminate boilerplate and generate type-safe code automatically.

$ npm install macroforge

Why Macroforge?

Bring the power of Rust-style derive macros to TypeScript

Built-in Macros

Debug, Clone, and Eq macros ready to use out of the box.

Custom Macros in Rust

Write your own derive macros using the full power of Rust.

IDE Integration

Full TypeScript plugin support with accurate error positions.

Zero Runtime

All code is generated at compile time. No runtime overhead.

Source Maps

Accurate position mapping from expanded code back to source.

Powered by SWC

Lightning-fast parsing and code generation with SWC.

See It In Action

Write less code, get more functionality

Before (Your Code)
TypeScript
import { Debug, Clone, PartialEq } from "macroforge";

/** @derive(Debug, Clone, PartialEq) */
class User {
	name: string;
	age: number;

	constructor(name: string, age: number) {
		this.name = name;
		this.age = age;
	}
}
After (Generated)
TypeScript
class User {
	name: string;
	age: number;

	constructor(name: string, age: number) {
		this.name = name;
		this.age = age;
	}

	toString(): string {
		const parts: string[] = [];
		parts.push("name: " + this.name);
		parts.push("age: " + this.age);
		return "User { " + parts.join(", ") + " }";
	}

	clone(): User {
		const cloned = Object.create(Object.getPrototypeOf(this));
		cloned.name = this.name;
		cloned.age = this.age;
		return cloned;
	}

	equals(other: unknown): boolean {
		if (this === other) return true;
		if (!(other instanceof User)) return false;
		const typedOther = other as User;
		return this.name === typedOther.name && this.age === typedOther.age;
	}
}

Built on Solid Foundations

Native performance with familiar tooling

Node.js / Vite / TypeScript Language Server
NAPI-RS Bindings
macroforge_ts_syn

Parsing

macroforge_ts_quote

Templating

macroforge_ts_macros

Proc Macro

SWC Core

TypeScript parsing & code generation

Ready to Get Started?

Install Macroforge and start generating code in minutes.

Read the Documentation