check
Создает действие проверки.
const Action = v.check<TInput, TMessage>(requirement, message);
Обобщения
TInputextends anyTMessageextends ErrorMessage<CheckIssue<TInput>> | undefined
Параметры
requirement(input: TInput) => booleanmessageTMessage
Объяснение
С помощью check можно свободно проверять входные данные и возвращать true, если они корректны, или false в противном случае. Если входные данные не соответствуют вашему requirement, можно использовать message, чтобы настроить сообщение об ошибке.
Возвращаемое значение
ActionCheckAction<TInput, TMessage>
Примеры
В следующих примерах показано, как можно использовать check.
Проверка свойств объекта
Схема для проверки свойств объекта.
const CustomObjectSchema = v.pipe(
v.object({
list: v.array(v.string()),
length: v.number(),
}),
v.check(
(input) => input.list.length === input.length,
'The list does not match the length.'
)
);
Связанные API
Следующие API можно комбинировать с check.
Схемы
any, array, bigint, blob, boolean, custom, date, enum, exactOptional, file, function, instance, intersect, lazy, literal, looseObject, looseTuple, map, nan, never, nonNullable, nonNullish, nonOptional, null, nullable, nullish, number, object, objectWithRest, optional, picklist, promise, record, set, strictObject, strictTuple, string, symbol, tuple, tupleWithRest, undefined, undefinedable, union, unknown, variant, void
Методы
Утилиты
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/check/