Skip to content

gunshi / combinators / unrequired

Function: unrequired()

ts
function unrequired<T>(schema): ArgSchema & Combinator<T> & CombinatorUnrequired;

Experimental

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.

Type Parameters

Type ParameterDescription
TThe schema's parsed type.

Parameters

ParameterTypeDescription
schemaCombinatorSchema<T>The base combinator schema.

Returns

ArgSchema & Combinator<T> & CombinatorUnrequired

A new schema with required: false.

Example

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

Released under the MIT License.