Turn a validator into a type guard
The validated type
The validator to convert
A validator makes a assertions about the input and returns a typed output. In contrast a guard is able to cast the type of the input for the rest of its block.
if (guard(isNumber)(input)) { // input is treated as a number in this block } Copy
if (guard(isNumber)(input)) { // input is treated as a number in this block }
Turn a validator into a type guard