Builder class

A builder pattern implementation with fluent interface.

Example

const obj = new Builder<MyObject>()
  .with("name", "John")
  .with("age", 30)
  .build();

Constructors

constructor constructor

Signature

<T extends Record<string, any>>(): Builder<T>

Type Parameters

T

The type being built

Methods

build method

Signature

(): T

Build the final object.

Returns

The constructed object

with method

Signature

<K extends string | number | symbol>(key: K, value: T[K]): this

Set a property value.

Parameters

key

The property name

value

The property value

Returns

This builder instance for chaining