Forger Help

Functions

Properties typed as functions are forged as callable stubs that return a forged value of the return type.

Callable properties

interface TaxCalculator { calc: (amount: number) => string; } const calculator = Forger.create<TaxCalculator>()!; // calculator.calc is a function const label = calculator.calc(100); // 'FS-W1}3E*L' — a forged string, freshly rolled per call

Every invocation forges a new value of the return type. Arguments are accepted and ignored — the stub is a data source, not a mock with behavior.

Return types are respected

Whatever the return type is, it follows the regular forging rules:

interface Service { now: () => Date; nextId: () => number; pick: () => 'a' | 'b' | 'c'; } const service = Forger.create<Service>()!; service.now(); // a Date in the configured window service.nextId(); // a random integer service.pick(); // 'a', 'b', or 'c'

Void and untyped returns

A function without a return type (() => void or a bare signature) forges as a callable returning null:

interface Handler { onError: () => void; } const handler = Forger.create<Handler>()!; handler.onError(); // null — safe to call, nothing to assert on

Functions vs methods

Only function-typed properties become callables. Class methods (greet(): string) are forged as data properties of the return type — calling them fails, because they are strings, not functions. To keep a method callable, pin it:

const gate = Forger.createWith<Gate>() .with(g => g.check = (ticket) => !!ticket) .result()!;

See Objects for what class forging includes and Caveats for the full list of quirks.

Forging a function directly

A top-level function type argument is forged the same way:

const factory = Forger.create<(id: number) => string>()!; factory(42); // a forged string
08 September 2026