Forger Help

Creating Fakes with Forger.create

Forger.create<T>() is the main entry point of the library. This topic covers its signature and calling conventions; the linked topics cover each type kind in detail.

Signature

static create<T>( settings: SpoofSettings = {}, circularDepth = 1, ...args: ForgerElement[] // technical, injected by the transformer ): T | undefined

Parameter

Meaning

settings

Optional tuning of numbers, strings, dates, and arrays — see Settings.

circularDepth

How deep circular type references are nested — see Circular references.

args

Technical: the injected type description. Never pass it manually.

The return type is T | undefined — the undefined branch covers builds where the transformer did not run. With a proper setup, use the non-null assertion: Forger.create<Student>()!.

Calling conventions

The first argument may be an inline object, a variable, or the result of a function call — all forms are preserved by the transformer:

// inline const a = Forger.create<string[]>({ arrayLength: 6 }); // variable const settings = { arrayLength: 6 }; const b = Forger.create<string[]>(settings); // function call const c = Forger.create<string[]>(getSettings());

Unspecified options fall back to defaults — an omitted settings behaves exactly like {}.

What gets generated

Every reachable property of T is forged, recursively:

interface Department { id: number; title: string } interface Employee { name: string; department: Department; tags: string[] } const employee = Forger.create<Employee>()!; // { // name: 'tR2#kW9!pL', // department: { id: 417, title: 'zQ1@mA0(xB' }, // tags: ['pLm3$kW9!tR', 'xQ1@mA0(zB2', 'kW9!tR2#pLm'] // }

Each call produces fresh random values — two create<Employee>() calls return two different employees of the same shape.

Type-by-type guides

For pinning concrete values, see createWith.

08 September 2026