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
Parameter | Meaning |
|---|---|
| Optional tuning of numbers, strings, dates, and arrays — see Settings. |
| How deep circular type references are nested — see Circular references. |
| 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:
Unspecified options fall back to defaults — an omitted settings behaves exactly like {}.
What gets generated
Every reachable property of T is forged, recursively:
Each call produces fresh random values — two create<Employee>() calls return two different employees of the same shape.
Type-by-type guides
Primitives —
string,number,boolean,null,undefinedObjects — interfaces, classes, what is included and what is not
Inheritance and generics — chains, substitutions, intersections
Arrays —
T[],Array<T>, nested arraysTuples — fixed-shape mixed arrays
Dates — windows and defaults
Enums — numeric and string enums
Literals — literal types and literal unions
Unions — random member selection
Functions — callable properties
Circular references — self-referencing types
For pinning concrete values, see createWith.