Type Alias: Validator()<T>
Validator<
T>: (value) =>value is T
Defined in: src/types/validation.ts:126
Type guard validator function.
Type Parameters
• T
Type to validate
Parameters
value
unknown
Returns
value is T
Remarks
A validator function that returns true if the value is of type T, false otherwise. TypeScript narrows the type when this function returns true.
This is a simple boolean validator. For detailed validation with error messages, use SchemaValidator instead.
Example
const isPositive: Validator<number> = (value): value is number => {
return typeof value === 'number' && value > 0;
};
const value: unknown = 5;
if (isPositive(value)) {
// TypeScript knows value is number here
console.log(value * 2);
}