or() function creates a higher-order guard that evaluates to true if any of the guards passed to it evaluate to true.
Signature
Parameters
An array of guards to evaluate. Each guard can be:
- A named guard string (e.g.,
'isValid') - A guard object with
typeand optionalparams - An inline guard function
Returns
A guard that returnstrue if any provided guard evaluates to true, otherwise false.
Usage
Basic Example
Mixing Named and Inline Guards
Fallback Validation
With Guard Parameters
Permission Checking
Nested Composition
Behavior
- Short-circuit evaluation: Once a guard returns
true, remaining guards are not evaluated - Empty array: An empty array is treated as
false(no guards passed) - Order matters: Guards are evaluated left-to-right until one returns
true - Performance: Place most likely conditions first for optimal performance
Type Safety
Theor() function maintains type safety across all guards:
See Also
- and - Logical AND for guards
- not - Logical NOT for guards
- Guards Overview - Introduction to guards