runtime-validator › Globals › "validator"
Ƭ CheckResult: Result.Result‹A, ValidatorError›
Result of the Validator.check
method.
On success returns Ok
with the validated value of type A
.
On failure returns Err
containing a ValidatorError
.
Ƭ ValidatorObject: object
Defines a mapped type over an interface A
. ValidatorObject<A>
is an
interface that has all the keys or A
, but each key's property type is
mapped to a validator for that type. This type is used when creating validators
for objects.
Example:
interface X {
a: boolean;
b: string;
}
const validatorObject: ValidatorObject<X> = {
a: tBoolean(),
b: tString()
}
▸ isValidator<A>(a
: any): a is Validator
Type guard for Validator
.
Type parameters:
▪ A
Parameters:
Name | Type |
---|---|
a |
any |
Returns: a is Validator
▸ isValidatorError(a
: any): a is ValidatorError
Type guard for ValidatorError
.
One use case of the type guard is in the catch
of a promise.
Typescript types the error argument of catch
as
any
, so when dealing with a validator as a promise you may need to
distinguish between a ValidatorError
and an error string.
Parameters:
Name | Type |
---|---|
a |
any |
Returns: a is ValidatorError