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
TSchemaextends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>
Parameters
schemaTSchema
Returns
examplesInferExamples<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
Actions
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/getExamples/