set
Creates a set schema.
const Schema = v.set<TValue, TMessage>(value, message);
Generics
TValueextends BaseSchema<unknown, unknown, BaseIssue<unknown>>TMessageextends ErrorMessage<SetIssue> | undefined
Parameters
valueTValuemessageTMessage
Explanation
With set you can validate the data type of the input and whether the content matches value. If the input is not a set, you can use message to customize the error message.
Returns
SchemaSetSchema<TValue, TMessage>
Examples
The following examples show how set can be used.
String set schema
Schema to validate a set with string values.
const StringSetSchema = v.set(v.string());
Object set schema
Schema to validate a set with object values.
const ObjectSetSchema = v.set(v.object({ key: v.string() }));
Related
The following APIs can be combined with set.
Schemas
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, strictObject, strictTuple, string, symbol, tuple, tupleWithRest, undefined, undefinedable, union, unknown, variant, void
Methods
assert, config, fallback, getDefault, getDefaults, getFallback, getFallbacks, is, message, parse, parser, pipe, safeParse, safeParser
Actions
check, brand, description, flavor, guard, maxSize, metadata, minSize, notSize, rawCheck, rawTransform, readonly, size, title, transform
Utils
entriesFromList, isOfKind, isOfType
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/set/