UNPKG

@ganbarodigital/ts-lib-value-objects

Version:

Helps you create value objects and refined types for safer software

40 lines 1.65 kB
import { OnError } from "@ganbarodigital/ts-lib-error-reporting/lib/v1"; import { DataGuarantee, ValueObject } from "../types"; /** * RefinedType is a base class for defining a subset of any given type. * The subset is defined by a contract / specification, and enforced by * a DataGuarantee. * * If you are refining a `string` or a `number`, use `RefinedString` or * `RefinedNumber` instead. They contain additional methods to help * JavaScript auto-resolve to the wrapped primitive in some circumstances. * * `T` is the type to be wrapped. */ export declare class RefinedType<T> extends ValueObject<T> { /** * define your own public constructor (or a static `from()` method if * you prefer that style, or want to support overloading) * * @param input * this is the value that will be stored, if it passes the * DataGuarantee * @param mustBe * this is the function that enforces the contract / specification * of this refined type * * child classes normally decide what this will be. You don't * normally allow the end-caller to pass this in. * @param onError * the error handler that gets called if the DataGuarantee * decides that the input doesn't meet the contract / * specification * * this is normally supplied by the end-caller. * * child classes can make this optional, and provide a default * error handler */ protected constructor(input: T, mustBe: DataGuarantee<T>, onError: OnError); } //# sourceMappingURL=RefinedType.d.ts.map