entriesFromList
Creates an object entries definition from a list of keys and a schema.
const entries = v.entriesFromList<TList, TSchema>(list, schema);
Generics
TListextends (string | number | symbol)[]TSchemaextends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>
Parameters
listTListschemaTSchema
Returns
entriesRecord<TList[number], TSchema>
Examples
The following example show how entriesFromList can be used.
const ObjectSchema = v.object(
v.entriesFromList(['foo', 'bar', 'baz'], v.string())
);
const ObjectSchemaWithSpread = v.object({
name: v.string(),
...v.entriesFromList(
['foo', 'bar', 'baz'],
v.pipe(v.string(), v.digits(), v.transform(Number))
),
});
Related
The following APIs can be combined with entriesFromList.
Schemas
any, array, bigint, blob, boolean, custom, date, enum, exactOptional, file, function, instance, intersect, 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, undefined, undefinedable, union, unknown, variant, void
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/entriesFromList/