not() function creates a higher-order guard that evaluates to true if the guard passed to it evaluates to false, and vice versa.
Signature
Parameters
A guard to invert. Can be:
- A named guard string (e.g.,
'isValid') - A guard object with
typeand optionalparams - An inline guard function
Returns
A guard that returns the opposite boolean value of the provided guard.Usage
Basic Example
Inline Guard Negation
Error Handling
With Guard Parameters
Authentication Check
Combining with Other Guards
Form Validation
Behavior
- Boolean inversion: Returns
trueif guard returnsfalse, andfalseif guard returnstrue - Single guard: Only accepts one guard argument (unlike
andandor) - Type preservation: Maintains the original guard’s type information
Common Patterns
Conditional Transitions
Availability Check
Type Safety
See Also
- and - Logical AND for guards
- or - Logical OR for guards
- Guards Overview - Introduction to guards