guard
guard<
T>(source,predicate,reason?):GuardSpec<T>
Defined in: extract/spec.ts:498
Validate a successfully extracted value against a predicate. Fails with ‘constraint’ kind if the predicate returns false.
Type Parameters
Section titled “Type Parameters”T extends Spec
Parameters
Section titled “Parameters”source
Section titled “source”T
predicate
Section titled “predicate”(value) => boolean
reason?
Section titled “reason?”string
Returns
Section titled “Returns”GuardSpec<T>
Example
Section titled “Example”guard( $.get('age').number(), v => (v as number) > 0, 'Age must be positive')