Forger Help

Objects: Interfaces and Classes

Interfaces, type literals, and classes are forged by walking their declared members. This topic explains exactly what gets included.

Interfaces

Every declared property is forged according to its type, including optional and readonly ones:

interface Student { readonly id: number; name: string; birthday?: Date; } const student = Forger.create<Student>()!; // { id: 941, name: 'tR2#kW9!pL', birthday: Date(2087-03-12) }

Classes

For classes, two sources of properties are used:

  • constructor parameters with modifiers (constructor(public name: string));

  • property declarations with a type annotation (age: number).

class Foo { constructor(public name: string) {} typed: string = 'initial'; optional?: Date; } const foo = Forger.create<Foo>()!; // { name: '…', typed: '…', optional: Date(…) } — initializers are ignored, types are used

What is not included:

Member

Behavior

static properties

Skipped — they belong to the class, not the instance

Fields without a type annotation (bar = 5)

Forged as null — there is no type to read

Methods (greet(): string)

Forged as a data property of the return type, not a callable — see Functions and Caveats

Getters / setters

Not treated as data; do not rely on them

If you need a callable member, declare it as a function-typed property (calc: (a: number) => string) or pin a real implementation with createWith.

Nested objects

Objects recurse: a property typed as another interface or class is forged the same way, to any depth. Circular (self-referencing) types stop at the configured depth — see Circular references.

Intersections

Intersection types combine the members of every side:

interface Base { field: null | string } type Extended = Base & { id?: number }; const obj = Forger.create<Extended>()!; // { field: '…', id: 417 }

Built-in structural types

Map, Set, Promise, and similar built-ins are forged structurally: their members — mostly methods — become data properties. The result type-checks but does not behave like a real Map. For behavioral doubles, pin real instances:

const repo = Forger.createWith<UserRepository>() .with(r => r.cache = new Map()) .result()!;

See Caveats for the full discussion.

08 September 2026