/** * get all optional (assignable to `undefined`) keys of the `T` type */ type OptionalKeys = { readonly [K in keyof T as string]-?: undefined extends T[K] ? K : never; }[string]; /** * @template Type the type on which the builder is based * @template Output the output type of the builder * @template Optional `build` closure is available only when all the keys of `Type` are optional */ export type Builder> = (Exclude extends never ? { /** * build the structure according to provided data */ readonly build: () => Output; } : {}) & { /** * @returns a new instance of the builder with the same data provided */ readonly clone: () => Builder; readonly with: /** * set the value of given property, * previously provided value (if any) will be overwritten * @param key key to change * @param value value to use */ ((key: Key, value: Type[Key]) => Builder) & /** * use the provided values, * previously provided values (if any) will be overwritten * @param data data to use */ (>(data: Data) => Builder); }; /** * @returns generic builder */ export declare function builder(): Builder; /** * @param factory factory closure which transforms collected data into another type * @returns generic builder */ export declare function builder(factory: (data: T) => O): Builder; /** * @param factory factory closure which transforms collected data into another type * @param defaults default values for the builder * @returns generic builder */ export declare function builder>(factory: (data: T) => O, defaults: D): Builder>; /** * @param factory factory closure which transforms collected data into another type * @param defaults default values for the builder * @returns generic builder */ export declare function builder>(factory: undefined, defaults: D): Builder>; export {};