intersect
Creates an intersect schema.
I recommend to read the intersections guide before using this schema function.
const Schema = v.intersect<TOptions, TMessage>(options, message);
Generics
TOptionsextends IntersectOptionsTMessageextends ErrorMessage<IntersectIssue> | undefined
Parameters
optionsTOptionsmessageTMessage
Explanation
With intersect you can validate if the input matches each of the given options. If the output of the intersection cannot be successfully merged, you can use message to customize the error message.
Returns
SchemaIntersectSchema<TOptions, TMessage>
Examples
The following examples show how intersect can be used.
Object intersection
Schema that combines two object schemas.
const ObjectSchema = v.intersect([
v.object({ foo: v.string() }),
v.object({ bar: v.number() }),
]);
Related
The following APIs can be combined with intersect.
Schemas
any, array, bigint, blob, boolean, custom, date, enum, exactOptional, file, function, instance, 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
assert, config, fallback, getDefault, getDefaults, getFallback, getFallbacks, is, message, parse, parser, pipe, safeParse, safeParser
Actions
args, base64, bic, brand, bytes, check, checkItems, codePoints, creditCard, cuid2, decimal, description, digits, domain, email, emoji, empty, endsWith, entries, everyItem, excludes, filterItems, findItem, finite, flavor, graphemes, gtValue, guard, hash, hexadecimal, hexColor, imei, includes, integer, ip, ipv4, ipv6, isbn, isrc, isoDate, isoDateTime, isoDateTimeSecond, isoTime, isoTimeSecond, isoTimestamp, isoWeek, ksuid, length, ltValue, mac, mac48, mac64, mapItems, maxBytes, maxCodePoints, maxEntries, maxGraphemes, maxLength, maxSize, maxValue, maxWords, metadata, mimeType, minBytes, minCodePoints, minEntries, minGraphemes, minLength, minSize, minValue, minWords, multipleOf, nanoid, nonEmpty, notBytes, notCodePoints, notEntries, notGraphemes, notLength, notSize, notValue, notValues, notWords, octal, parseJson, partialCheck, rawCheck, rawTransform, readonly, reduceItems, regex, returns, rfcEmail, safeInteger, size, slug, someItem, sortItems, startsWith, stringifyJson, title, toCamelCase, toKebabCase, toLowerCase, toMaxValue, toMinValue, toPascalCase, toSnakeCase, toUpperCase, transform, trim, trimEnd, trimStart, ulid, url, uuid, value, values, words
Utils
entriesFromList, isOfKind, isOfType
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/intersect/