---
title: flatten
description: Flatten the error messages of issues.
source: /methods/flatten/flatten.ts
contributors:
  - fabian-hiller
---

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

# flatten

Flatten the error messages of issues.

```ts
const errors = v.flatten<TSchema>(issues);
```

## Generics

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

## Parameters

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

### Explanation

The error messages of issues without a path that belong to the root of the schema are added to the `.root` key.

The error messages of issues with a path that belong to the nested parts of the schema and can be converted to a dot path are added to the `.nested` key.

Some issue paths, for example for complex data types like `Set` and `Map`, have no key or a key that cannot be converted to a dot path. These error messages are added to the `.other` key.

## Returns

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

## Examples

The following example show how `flatten` can be used.

```ts
const Schema = v.object({
  nested: v.object({
    foo: v.string('Value of "nested.foo" is invalid.'),
  }),
});

const result = v.safeParse(Schema, { nested: { foo: null } });

if (result.issues) {
  const flatErrors = v.flatten<typeof Schema>(result.issues);

  // ...
}
```

## Related

The following APIs can be combined with `flatten`.

### Methods

<ApiList items={['parse', 'parser', 'safeParse']} />
