Spec-Zone.ru › Valibot

instance

Creates an instance schema.

const Schema = v.instance<TClass, TMessage>(class_, message);

Generics

  • TClass extends Class
  • TMessage extends ErrorMessage<InstanceIssue> | undefined

Parameters

  • class_ TClass
  • message TMessage

Explanation

With instance you can validate the data type of the input. If the input is not an instance of the specified class_, you can use message to customize the error message.

Returns

  • Schema InstanceSchema<TClass, TMessage>

Examples

The following examples show how instance can be used.

Error schema

Schema to validate an Error instance.

const ErrorSchema = v.instance(Error, 'Error instance required.');

File schema

Schema to validate an File instance.

const FileSchema = v.pipe(
  v.instance(File),
  v.mimeType(['image/jpeg', 'image/png']),
  v.maxSize(1024 * 1024 * 10)
);

Related

The following APIs can be combined with instance.

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

Actions

check, brand, description, flavor, gtValue, ltValue, maxSize, maxValue, metadata, mimeType, minSize, minValue, notSize, notValue, notValues, rawCheck, rawTransform, readonly, size, title, toMaxValue, toMinValue, transform, value, values

Utils

entriesFromList, isOfKind, isOfType

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

Spec-Zone.ru

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