﻿<head><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4357510538660394"
     crossorigin="anonymous"></script></head># checkItemsAsync

> This document is the Markdown version of [valibot.dev/api/checkItemsAsync/](https://valibot.dev/api/checkItemsAsync/). For the complete documentation index, see [llms.txt](https://valibot.dev/llms.txt).

Creates a check items validation action.

```ts
const Action = v.checkItemsAsync<TInput, TMessage>(requirement, message);
```

## Generics

- `TInput` `extends ArrayInput`
- `TMessage` `extends ErrorMessage<CheckItemsIssue<TInput>> | undefined`

## Parameters

- `requirement` `ArrayRequirementAsync<TInput>`
- `message` `TMessage`

### Explanation

With `checkItemsAsync` you can freely validate the items of an array and return `true` if they are valid or `false` otherwise. If an item does not match your `requirement`, you can use `message` to customize the error message.

> The special thing about `checkItemsAsync` is that it automatically forwards each issue to the appropriate item.

## Returns

- `Action` `CheckItemsActionAsync<TInput, TMessage>`

## Examples

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

### Cart items schema

Schema to check an array of cart item objects.

```ts
import { getProductItem } from '~/api';

const CartItemsSchema = v.pipeAsync(
  v.array(
    v.object({
      itemId: v.pipe(v.string(), v.uuid()),
      quantity: v.pipe(v.number(), v.minValue(1)),
    })
  ),
  v.checkItemsAsync(async (input) => {
    const productItem = await getProductItem(input.itemId);
    return (productItem?.quantity ?? 0) >= input.quantity;
  }, 'The required quantity is greater than available.')
);
```

## Related

The following APIs can be combined with `checkItemsAsync`.

### Schemas

[`any`](/api/any.md), [`array`](/api/array.md), [`custom`](/api/custom.md), [`instance`](/api/instance.md), [`tuple`](/api/tuple.md), [`unknown`](/api/unknown.md)

### Utils

[`isOfKind`](/api/isOfKind.md), [`isOfType`](/api