Spec-Zone.ru › Valibot

looseTuple

Creates a loose tuple schema.

const Schema = v.looseTuple<TItems, TMessage>(items, message);

Generics

  • TItems extends TupleItems
  • TMessage extends ErrorMessage<LooseTupleIssue> | undefined

Parameters

  • items TItems
  • message TMessage

Explanation

With looseTuple you can validate the data type of the input and whether the content matches items. If the input is not an array, you can use message to customize the error message.

The difference to tuple is that this schema does include unknown items into the output.

Returns

  • Schema LooseTupleSchema<TItems, TMessage>

Examples

The following examples show how looseTuple can be used. Please see the arrays guide for more examples and explanations.

Simple tuple schema

Schema to validate a loose tuple with two specific items.

const SimpleTupleSchema = v.looseTuple([v.string(), v.number()]);

Related

The following APIs can be combined with looseTuple.

Schemas

any, array, bigint, blob, boolean, custom, date, enum, exactOptional, file, function, instance, intersect, lazy, literal, looseObject, 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

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

© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/looseTuple/

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API