Spec-Zone.ru › Valibot

entriesFromList

Creates an object entries definition from a list of keys and a schema.

const entries = v.entriesFromList<TList, TSchema>(list, schema);

Generics

  • TList extends (string | number | symbol)[]
  • TSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>

Parameters

  • list TList
  • schema TSchema

Returns

  • entries Record<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/

Spec-Zone.ru

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