Skip to content

gunshi / combinators / withDefault

Function: withDefault()

ts
function withDefault<T>(schema, defaultValue): ArgSchema & Combinator<T> & CombinatorWithDefault<T>;

Experimental

Set a default value on a combinator schema.

The original schema is not modified.

Type Parameters

Type ParameterDescription
T extends string | number | booleanThe schema's parsed type.

Parameters

ParameterTypeDescription
schemaCombinatorSchema<T>The base combinator schema.
defaultValueTThe default value.

Returns

ArgSchema & Combinator<T> & CombinatorWithDefault<T>

A new schema with the default value set.

Example

ts
const args = {
  port: withDefault(integer({ min: 1, max: 65535 }), 8080)
}

Released under the MIT License.