merge

Merges the entries of multiple object schemas. Subsequent object entries overwrite the previous ones.

// Object schema with an optional pipe
const Schema = merge<TSchemas>(schemas, pipe);

// Object schema with an optional message and pipe
const Schema = merge<TSchemas>(schemas, message, pipe);

// Object schema with rest and optional pipe
const Schema = merge<TSchemas, TRest>(schemas, rest, pipe);

// Object schema with rest and optional message and pipe
const Schema = merge<TSchemas, TRest>(schemas, rest, message, pipe);

Generics

Parameters

Explanation

merge creates a new object schema where the entries of the provided object schemas are merged.

Note that rest, message and pipe of the passed schemas are completely ignored and must be added again.

Returns

Examples

The following examples show how merge can be used.

Merged object schema

Schema that contains the merged entries of two object schemas.

Note that the baz entry of the second object schema overwrites the baz entry of the first object schema.

const MergedObjectSchema = merge([
  object({ foo: string(), baz: number() }),
  object({ bar: string(), baz: boolean() }),
]); // { foo: string; bar: string; baz: boolean }

The following APIs can be combined with merge.

Schemas

Methods

Transformations

Validations

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 dailydotdev
  • GitHub profile picture of ivan-mihalic
  • GitHub profile picture of KATT
  • GitHub profile picture of osdiab
  • GitHub profile picture of Thanaen
  • GitHub profile picture of hyunbinseo
  • GitHub profile picture of caegdeveloper