API Stability Notice

Macroforge is under active development. The API is not yet stable and may change between versions. Some documentation sections may be outdated.

Installation

Get started with Macroforge in just a few minutes. Install the package and configure your project to start using TypeScript macros.

Requirements

  • Node.js 24.0 or later
  • TypeScript 5.9 or later

Install the Package

Install Macroforge using your preferred package manager:

npm
npm install macroforge
bun
bun add macroforge
pnpm
pnpm add macroforge
Info
Macroforge includes pre-built native binaries for macOS (x64, arm64), Linux (x64, arm64), and Windows (x64, arm64).

Basic Usage

The simplest way to use Macroforge is with the built-in derive macros. Add a @derive comment decorator to your class:

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

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

// After macro expansion, User has:
// - toString(): string              (from Debug)
// - clone(): User                   (from Clone)
// - equals(other: unknown): boolean (from PartialEq)

IDE Integration

For the best development experience, add the TypeScript plugin to your tsconfig.json:

tsconfig.json
{
  "compilerOptions": {
    "plugins": [
      {
        "name""@macroforge/typescript-plugin"
      }
    ]
  }
}

This enables features like:

  • Accurate error positions in your source code
  • Autocompletion for generated methods
  • Type checking for expanded code

Build Integration (Vite)

If you're using Vite, add the plugin to your config for automatic macro expansion during build:

vite.config.ts
import macroforge from "@macroforge/vite-plugin";
import { defineConfig } from "vite";

export default defineConfig({
  plugins: [
    macroforge({
      generateTypes: true,
      typesOutputDir: ".macroforge/types"
    })
  ]
});

Next Steps

Now that you have Macroforge installed, learn how to use it: