Skip to main content

CreateErrorResultGuard

createErrorResultGuard

Convenience method for creating an ErrorResultGuard. Takes a predicate function which tests whether the input is considered successful (true) or an error result (false).

Note that the resulting variable must still be type annotated in order for the TypeScript type inference to work as expected:

Example

const orderResultGuard: ErrorResultGuard<AddItemToOrderResult>
= createErrorResultGuard(order => !!order.lines);
Signature
function createErrorResultGuard<T>(testFn: (input: T) => boolean): ErrorResultGuard<T>

Parameters

testFn

parameter
(input: T) => boolean