TypeScript Macros, Generated at Build Time

Push code generation to compile time for faster runtime and safer code. Eliminate boilerplate with zero runtime overhead.

$ npm install macroforge

Why Macroforge?

Move work from runtime to build time for better performance and safety

Zero Runtime Cost

All code generation happens at build time. Ship only the code you need.

Type-Safe Generation

Catch errors during compilation, not at runtime. Full TypeScript integration.

Built-in Macros

Debug, Clone, Serialize, and more ready to use out of the box.

IDE Integration

Full TypeScript plugin support with accurate error positions.

Source Maps

Accurate position mapping from expanded code back to source.

Extensible

Write custom macros in TypeScript or Rust to fit your needs.

See It In Action

Write less code, get more functionality

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

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

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

    static toString(value: User): string {
        return userToString(value);
    }

    static clone(value: User): User {
        return userClone(value);
    }

    static equals(a: User, b: User): boolean {
        return userEquals(a, b);
    }
}

export function userToString(value: User): string {
    const parts: string[] = [];
    parts.push('name: ' + value.name);
    parts.push('age: ' + value.age);
    return 'User { ' + parts.join(', ') + ' }';
}

export function userClone(value: User): User {
    const cloned = Object.create(Object.getPrototypeOf(value));
    cloned.name = value.name;
    cloned.age = value.age;
    return cloned;
}

export function userEquals(a: User, b: User): boolean {
    if (a === b) return true;
    return a.name === b.name && a.age === b.age;
}

Build Time, Not Runtime

Generate code once during build, run it everywhere with zero overhead

At Build Time

  • Parse decorators and type definitions
  • Generate serializers, validators, and utilities
  • Validate types and catch errors early
  • Output optimized, tree-shakeable code

At Runtime

  • No reflection or metadata overhead
  • No decorator libraries to bundle
  • Plain JavaScript functions, fully inlineable
  • Errors caught at build time, not in production

Unlike runtime decorator libraries that use reflection, Macroforge generates plain TypeScript that compiles to efficient JavaScript with no hidden costs.

Ready to Get Started?

Install Macroforge and start generating code in minutes.

Read the Documentation