Skip to content

Function: withDefault() ​

WARNING

This API is experimental and may change in future versions.

Set a default value on a combinator schema.

The original schema is not modified.

Signature ​

ts
declare function withDefault<T extends string | boolean | number>(schema: CombinatorSchema<T>, defaultValue: T): CombinatorSchema<T> & CombinatorWithDefault<T>

Type Parameters ​

NameDescription
T extends string | boolean | numberThe schema's parsed type.

Parameters ​

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

Returns ​

CombinatorSchema<T> & CombinatorWithDefault<T> — A new schema with the default value set.

Examples ​

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

Released under the MIT License.