Spec-Zone.ru › Valibot

getExamples

Returns the examples of the schema.

If multiple examples are defined, it concatenates them using depth-first search. If no examples are defined, an empty array is returned.

const examples = v.getExamples<TSchema>(schema);

Generics

  • TSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>

Parameters

  • schema TSchema

Returns

  • examples InferExamples<TSchema>

Examples

The following examples show how getExamples can be used.

String schema

const StringSchema = v.pipe(v.string(), v.examples(['foo', 'bar', 'baz']));

const examples = v.getExamples(StringSchema);

// ['foo', 'bar', 'baz']

Nested schema

const NestedSchema = v.pipe(
  v.string(),
  v.examples(['foo', 'bar', 'baz']),
  v.pipe(v.string(), v.examples(['qux', 'quux']))
);

const examples = v.getExamples(NestedSchema);

// ['foo', 'bar', 'baz', 'qux', 'quux']

Related

The following APIs can be combined with getExamples.

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, set, strictObject, strictTuple, string, symbol, tuple, tupleWithRest, undefined, undefinedable, union, unknown, variant, void

Methods

pipe

Actions

examples

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

Spec-Zone.ru

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