flatten

Flatten the error messages of issues.

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

Generics

Parameters

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

Examples

The following example show how flatten can be used.

const Schema = v.object({
  nested: v.object({
    key: v.string('Value of "nested.key" is missing.'),
  }),
});

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

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

  // ...
}

The following APIs can be combined with flatten.

Methods

Contributors

Thanks to all the contributors who helped make this page better!

  • GitHub profile picture of fabian-hiller

Partners

Thanks to our partners who support the project ideally and financially.

Sponsors

Thanks to our GitHub sponsors who support the project financially.

  • GitHub profile picture of antfu
  • GitHub profile picture of Thanaen
  • GitHub profile picture of osdiab
  • GitHub profile picture of ruiaraujo012
  • GitHub profile picture of hyunbinseo
  • GitHub profile picture of F0rce
  • GitHub profile picture of fabulousgk
  • GitHub profile picture of jdgamble555
  • GitHub profile picture of isoden
  • GitHub profile picture of nickytonline
  • GitHub profile picture of caegdeveloper
  • GitHub profile picture of luckasnix
  • GitHub profile picture of andrew-3kb
  • GitHub profile picture of dslatkin