import { BuilderHandler, BuilderHandlerOverride, BuilderIncompleteProduct, BuilderProductKey } from "./types"; /** * Builder for an object. * It can replace the creation of a simple object or a multi-level class hierarchy. * * @template Pattern is the product expected from the {@link ObjectBuilder}. * @template Product is the actual object that will be builded (product) for an {@link ObjectBuilder} instance. */ export declare class ObjectBuilder, const Product extends Record> { private readonly handlers; /** * Creates An {@link ObjectBuilder}. * * @returns An {@link ObjectBuilder} */ static create>(): ObjectBuilder>; private constructor(); /** * Builds the product of this builder. * * Useful in typescript as it ensure that all necessary keys have been set. * * @example * // `a` is of type `NonExhaustiveProduct` * const a = ObjectBuilder.create<{ a: number }>() * .build(); * @example * // `a` satisfies `{ a: number }` * const a = ObjectBuilder.create<{ a: number }>() * .with("a", () => 0) * .build(); * @example * // `b` is of type `NonExhaustiveProduct` * const b = ObjectBuilder.create() * .with("a", () => 0) * .build<{ b: number }>(); * @example * // `b` satisfies `{ b: number }` (and `{ a: number; b: number }`) * const b = ObjectBuilder.create() * .with("a", () => 0) * .with("b", () => 0) * .build<{ b: number }>(); * @example * // `c` satisfies `{ a: number }` * const c = ObjectBuilder.create<{ a: number; c: number }>() * .with("a", () => 0) * .build(); * * @template P Constraint: does the builded product satisfy `P` ? * Use `unknown` to ignore this constraint. * @returns the final product */ build

(): Product extends P ? Product : BuilderIncompleteProduct; /** * Returns the currently set keys * * @returns the currently set keys */ keys(): Array; /** * Adds a [handler]{@link BuilderHandler} on the call of a given key. * * @param key to add * @param handler for the given key * @returns a new builder with the added handler */ with(key: Key, handler: BuilderHandler & Pattern, T>): ObjectBuilder & Record>; /** * Adds a [handler]{@link BuilderHandler} on the call of a given key. * * @param key to add * @param handler for the given key * @returns a new builder with the added handler */ with(key: Key, handler: BuilderHandler & Pattern & Record, T>): ObjectBuilder & Record>; /** * Overrides an existing key [handler]{@link BuilderHandler}. * * The other handlers that refer to this key will also use this handler. * * @param key to override * @param handler for the given key * @throws {OverrideUnsetKeyException} when the key is not already set * @returns a new builder with the overridden key */ override(key: Key, handler: BuilderHandlerOverride): this; }