---
title: map
description: Creates a map schema.
source: /schemas/map/map.ts
contributors:
  - fabian-hiller
---

import { ApiList, Property } from '~/components';
import { properties } from './properties';

# map

Creates a map schema.

```ts
const Schema = v.map<TKey, TValue, TMessage>(key, value, message);
```

## Generics

- `TKey` <Property {...properties.TKey} />
- `TValue` <Property {...properties.TValue} />
- `TMessage` <Property {...properties.TMessage} />

## Parameters

- `key` <Property {...properties.key} />
- `value` <Property {...properties.value} />
- `message` <Property {...properties.message} />

### Explanation

With `map` you can validate the data type of the input and whether the entries matches `key` and `value`. If the input is not a map, you can use `message` to customize the error message.

## Returns

- `Schema` <Property {...properties.Schema} />

## Examples

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

### String map schema

Schema to validate a map with string values.

```ts
const StringMapSchema = v.map(v.string(), v.string());
```

### Object map schema

Schema to validate a map with object values.

```ts
const ObjectMapSchema = v.map(v.string(), v.object({ key: v.string() }));
```

## Related

The following APIs can be combined with `map`.

### Schemas

<ApiList
  items={[
    'any',
    'array',
    'bigint',
    'blob',
    'boolean',
    'custom',
    'date',
    'enum',
    'exactOptional',
    'file',
    'function',
    'instance',
    'intersect',
    'lazy',
    'literal',
    'looseObject',
    'looseTuple',
    'nan',
    'never',
    'nonNullable',
    'nonNullish',
    'nonOptional',
    'null',
    'nullable',
    'nullish',
    'number',
    'object',
    'objectWithRest',
    'optional',
    'picklist',
    'promise',
    'record',
    'set',
    'strictObject',
    'strictTuple',
    'string',
    'symbol',
    'tuple',
    'tupleWithRest',
    'undefined',
    'undefinedable',
    'union',
    'unknown',
    'variant',
    'void',
  ]}
/>

### Methods

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

### Actions

<ApiList
  items={[
    'check',
    'brand',
    'description',
    'flavor',
    'guard',
    'maxSize',
    'metadata',
    'minSize',
    'notSize',
    'rawCheck',
    'rawTransform',
    'readonly',
    'size',
    'title',
    'transform',
  ]}
/>

### Utils

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