Skip to content

Function: unrequired()

WARNING

This API is experimental and may change in future versions.

Mark a combinator schema as not required.

Useful for overriding a base combinator that was created with required: true. The original schema is not modified.

Signature

ts
declare function unrequired<T>(schema: CombinatorSchema<T>): CombinatorSchema<T> & CombinatorUnrequired

Type Parameters

NameDescription
TThe schema's parsed type.

Parameters

NameTypeDescription
schemaCombinatorSchema<T>The base combinator schema.

Returns

CombinatorSchema<T> & CombinatorUnrequired — A new schema with required: false.

Examples

ts
const args = {
  name: unrequired(string({ required: true }))
}

Released under the MIT License.