# instance

Creates an instance schema.

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

## Generics

- `TClass` <Property {...properties.TClass} />
- `TMessage` <Property {...properties.TMessage} />

## Parameters

- `class_` {/* prettier-ignore */}<Property {...properties.class_} />
- `message` <Property {...properties.message} />

### 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` <Property {...properties.Schema} />

## Examples

The following examples show how `instance` can be used.

### Error schema

Schema to validate an `Error` instance.

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

### File schema

Schema to validate an `File` instance.

```ts
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

<ApiList
  items={[
    'array',
    'exactOptional',
    'intersect',
    'lazy',
    'looseObject',
    'looseTuple',
    'map',
    'nonNullable',
    'nonNullish',
    'nonOptional',
    'nullable',
    'nullish',
    'object',
    'objectWithRest',
    'optional',
    'record',
    'set',
    'strictObject',
    'strictTuple',
    'tuple',
    'tupleWithRest',
    'undefinedable',
    'union',
  ]}
/>

### Methods

<ApiList
  items={[
    'assert',
    'config',
    'fallback',
    'getDefault',
    'getDefaults',
    'getFallback',
    'getFallbacks',
    'is',
    'message',
    'parse',
    'parser',
    'pipe',
    'safeParse',
    'safeParser',
  ]}
/>

### Actions

<ApiList
  items={[
    '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

<ApiList items={['entriesFromList', 'isOfKind', 'isOfType']} />
