Forger Help

Installation

Forger consists of two parts: a runtime factory and a compile-time TypeScript transformer. The transformer is what makes Forger.create<T>() type-aware, so installing the package is only half of the story — the build pipeline has to apply the transformer as well.

Prerequisites

  • A supported TypeScript line: 5.x/6.x for Forger 2, 4.x for Forger 1 — see Versions for the full matrix.

  • A build that applies custom transformers: ts-jest, ts-patch, or the Angular plugin (see Integration).

1. Install the package

Install the line matching your TypeScript generation:

# TypeScript 5 or 6 — current line (branch v2) npm install --save-dev @artstesh/forger # TypeScript 4 — legacy line (branch v1) npm install --save-dev @artstesh/forger@^1

Forger has no runtime dependencies, so nothing else lands in your dependency tree.

2. Install ts-patch

The transformer is applied through ts-patch, which teaches the TypeScript compiler to run transformers declared in tsconfig.json. ts-patch's major must match your TypeScript major:

# TypeScript 6+ npm install --save-dev ts-patch@^4 # TypeScript 5 npm install --save-dev ts-patch@^3

3. Declare the transformer in tsconfig.json

Add the transformer to the plugins section of the compiler options:

{ "compilerOptions": { "plugins": [ { "transform": "@artstesh/forger/lib/utils/transformer" } ] } }

This single entry covers all build flavors that respect plugins: ts-patch CLI builds, ts-jest with the ts-patch compiler, and the Angular integration shipped with Forger.

4. Wire up your test runner

For Jest with ts-jest, point the compiler at ts-patch and register the transformer:

/** jest.config.js */ module.exports = { preset: 'ts-jest', transform: { '.*.spec.ts': ['ts-jest', { compiler: 'ts-patch/compiler', astTransformers: { before: ['@artstesh/forger/lib/utils/transformer'] } }] } };

Step-by-step instructions for every supported pipeline live in Integration with Jest, Integration with Angular, and Building with ts-patch.

5. Verify the setup

Create a spec and run the test suite:

import { Forger } from '@artstesh/forger'; it('forger is wired up', () => { const name = Forger.create<string>(); // expect(typeof name).toBe('string'); });

If the test fails with name being undefined, the transformer is not applied — revisit step 3 and 4, and clear the Jest transform cache (jest --clearCache) after changing transformer configuration. Without the transformer, Forger.create<T>() always returns undefined (see Caveats).

Next steps

Continue with the Quick Start to forge your first object.

08 September 2026