@ganbarodigital/ts-lib-value-objects
Version:
Helps you create value objects and refined types for safer software
26 lines • 1.23 kB
TypeScript
import { AnyAppError, OnError } from "@ganbarodigital/ts-lib-error-reporting/lib/v1";
/**
* A DataCoercion inspects the given data, to see if the given data
* meets a defined contract / specification.
*
* If the given data does meet the given contract / specification, the
* DataCoercion returns the given data.
*
* If the given data does not meet the given contract / specification,
* the DataCoercion calls the supplied OnError handler. The OnError
* handler can do any of the following:
*
* a) it can throw an Error (ie it never returns), or
* b) it can return a value that does meet the given contract / specification
*
* `T` is the type of data to be inspected
* `GR` is the return type of the data guarantee function
* - it *must* be compatible with `T` in some way
* - `GR` is also the return type of the supplied `OnError` handler
*
* When you implement a DataCoercion, make it a wrapper around one or more
* TypeGuards and/or DataGuards - and even other DataCoercions if
* appropriate. That's the best way to make your code as reusable as possible.
*/
export declare type DataCoercion<T, GR extends T = T> = (input: T, onError: OnError<AnyAppError, GR>) => GR;
//# sourceMappingURL=DataCoercion.d.ts.map