@darlean/valueobjects
Version:
Library for DDD-like value objects that can be validated, serialized and represented in other programming languages as native objects with native naming.
25 lines (24 loc) • 982 B
TypeScript
export type CanonicalFieldName = string;
export type CanonicalType = string;
export declare class ValidationError extends Error {
}
export type Class<T> = {
new (...args: any[]): T;
name: string;
};
/**
* Constant that indicates that a class must be structurally typed (instead of nominally typed
* (aka duck-typed) as used by javascript.
* Without structurally typing, the TS compiler will not warm you when assign a value object
* of one type (say 'first-name') to a value that expects another type (say 'last-name'), both of type string.
*
* @example
* ```
* @stringvalue class FirstName extends StringValue { first_name = discriminative }
* @stringvalue class LastName extends StringValue { last_name = discriminative }
* let a: FirstName = FirstName.from('Alice);
* a = LastName.from('Jansen'); // ==> Will not compile
* ```
*/
export type discriminative = undefined;
export declare function deriveTypeName(name: string): string;