Spec-Zone.ru › Valibot

keyof

Creates a picklist schema of object keys.

const Schema = v.keyof<TSchema, TMessage>(schema, message);

Generics

  • TSchema extends LooseObjectSchema<ObjectEntries, ErrorMessage<ObjectIssue> | undefined> | LooseObjectSchemaAsync<ObjectEntriesAsync, ErrorMessage<ObjectIssue> | undefined> | ObjectSchema<ObjectEntries, ErrorMessage<ObjectIssue> | undefined> | ObjectSchemaAsync<ObjectEntriesAsync, ErrorMessage<ObjectIssue> | undefined> | ObjectWithRestSchema<ObjectEntries, BaseSchema<unknown, unknown, BaseIssue<unknown>>, ErrorMessage<ObjectWithRestIssue> | undefined> | ObjectWithRestSchemaAsync<ObjectEntriesAsync, BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, ErrorMessage<ObjectWithRestIssue> | undefined> | StrictObjectSchema<ObjectEntries, ErrorMessage<ObjectIssue> | undefined> | StrictObjectSchemaAsync<ObjectEntriesAsync, ErrorMessage<ObjectIssue> | undefined>
  • TMessage ErrorMessage<PicklistIssue> | undefined

Parameters

  • schema TSchema
  • message TMessage

Returns

  • Schema PicklistSchema<ObjectKeys<TSchema, TMessage>>

Examples

The following examples show how keyof can be used.

Object key schema

Schema to validate the keys of an object.

const ObjectSchema = v.object({ key1: v.string(), key2: v.number() });
const ObjectKeySchema = v.keyof(ObjectSchema); // 'key1' | 'key2'

Related

The following APIs can be combined with keyof.

Schemas

array, exactOptional, intersect, lazy, looseObject, looseTuple, map, nonNullable, nonNullish, nonOptional, nullable, nullish, object, objectWithRest, optional, record, set, strictObject, strictTuple, tuple, tupleWithRest, undefinedable, union

Methods

assert, config, fallback, getDefault, getDefaults, getFallback, getFallbacks, is, message, parse, parser, pipe, safeParse, safeParser, unwrap

Actions

check, brand, description, flavor, guard, metadata, rawCheck, rawTransform, readonly, title, transform

Utils

isOfKind, isOfType

Async

arrayAsync, customAsync, exactOptionalAsync, fallbackAsync, intersectAsync, lazyAsync, looseObjectAsync, looseTupleAsync, mapAsync, nonNullableAsync, nonNullishAsync, nonOptionalAsync, nullableAsync, nullishAsync, objectAsync, objectWithRestAsync, optionalAsync, partialAsync, pipeAsync, recordAsync, requiredAsync, setAsync, strictObjectAsync, strictTupleAsync, tupleAsync, tupleWithRestAsync, unionAsync, variantAsync

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

Spec-Zone.ru

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