Forger Help

API Reference: CreateWithModel

The builder returned by Forger.createWith<T>(). It carries a pre-generated instance of T and applies pinned property values to it.

class CreateWithModel<T> { with(expr: (prop: T) => void): CreateWithModel<T>; result(): T | undefined; }

with

with(expr: (prop: T) => void): CreateWithModel<T>

Executes expr against the generated instance. Use exactly one property assignment per call and chain calls for multiple properties:

const student = Forger.createWith<Student>() .with(s => s.name = 'John Doe') .with(s => s.age = 42) .result();

Nested paths are allowed and count as a single assignment:

.with(s => s.address.city = 'Berlin')

The expression runs immediately, so the values on the right side are evaluated at with() time, not at result() time.

result

result(): T | undefined

Returns the instance after all with() calls. Call it after every with() — later assignments are not applied. Like Forger.create, the return type includes undefined for the no-transformer scenario.

Interaction with generation

The transformer inspects the with() expressions of the whole chain and excludes pinned properties from generation for the root type instance — the assigned value is the only one the property will hold. Everything else about the instance stays generated, including same-named properties in nested objects. Details: createWith.

08 September 2026