arrayAsync
Creates an array schema.
const Schema = v.arrayAsync<TItem, TMessage>(item, message);
Generics
TItemextends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>TMessageextends ErrorMessage<ArrayIssue> | undefined
Parameters
itemTItemmessageTMessage
Explanation
With arrayAsync you can validate the data type of the input. If the input is not an array, you can use message to customize the error message.
If your array has a fixed length, consider using
tupleAsyncfor a more precise typing.
Returns
SchemaArraySchemaAsync<TItem, TMessage>
Examples
The following examples show how arrayAsync can be used.
Stored emails schema
Schema to validate an array of stored emails.
import { isEmailPresent } from '~/api';
const StoredEmailsSchema = v.arrayAsync(
v.pipeAsync(
v.string(),
v.email(),
v.checkAsync(isEmailPresent, 'The email is not in the database.')
)
);
Related
The following APIs can be combined with arrayAsync.
Schemas
any, 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
Methods
config, getDefault, getFallback
Actions
check, checkItems, brand, description, empty, everyItem, excludes, filterItems, findItem, flavor, guard, includes, length, mapItems, maxLength, metadata, minLength, nonEmpty, notLength, partialCheck, rawCheck, rawTransform, readonly, reduceItems, someItem, sortItems, title, transform
Utils
entriesFromList, isOfKind, isOfType
Async
checkAsync, customAsync, exactOptionalAsync, fallbackAsync, getDefaultsAsync, getFallbacksAsync, intersectAsync, lazyAsync, looseObjectAsync, looseTupleAsync, mapAsync, nonNullableAsync, nonNullishAsync, nonOptionalAsync, nullableAsync, nullishAsync, objectAsync, objectWithRestAsync, optionalAsync, parseAsync, parserAsync, partialCheckAsync, pipeAsync, rawCheckAsync, rawTransformAsync, recordAsync, safeParseAsync, safeParserAsync, setAsync, strictObjectAsync, strictTupleAsync, transformAsync, tupleAsync, tupleWithRestAsync, unionAsync, variantAsync
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/arrayAsync/