domain-objects
Version:
A simple, convenient way to represent domain objects, leverage domain knowledge, and add runtime validation in your code base.
28 lines (27 loc) • 984 B
TypeScript
/**
* .what = wrappers which add immutability mechs on dobj instances
*/
export type WithImmute<T> = T & {
clone(updates?: Partial<T>): WithImmute<T>;
};
/**
* .what = adds immute operations (.clone) to domain objects
* .why = enables immutable updates for safer, more maintainable code
*
* variants:
* - withImmute(value) = recursive (default, pit of success)
* - withImmute.recursive(value) = explicit recursive
* - withImmute.singular(obj) = single object only (shallow)
*/
export declare const withImmute: (<T>(value: T) => WithImmute<T>) & {
recursive: <T>(value: T) => WithImmute<T>;
singular: <T_1 extends Record<string, any>>(obj: T_1) => WithImmute<T_1>;
};
/**
* .what = alias for withImmute
* .why = intuitive name for what it does (adds .clone())
*/
export declare const withClone: (<T>(value: T) => WithImmute<T>) & {
recursive: <T>(value: T) => WithImmute<T>;
singular: <T_1 extends Record<string, any>>(obj: T_1) => WithImmute<T_1>;
};