Skip to content

Function: integer() ​

Call Signature ​

ts
export declare function integer<const R extends boolean>(opts: IntegerOptions & {
  required: R;
}): WithRequiredOption<CombinatorSchema<number>, R>

Create an integer argument schema with optional range validation.

Only accepts integer values (no decimals).

Type Parameters ​

NameDescription
R extends booleanThe type of required in the options, which the schema keeps.

Parameters ​

NameTypeDescription
optsIntegerOptions & { required: R }Range options.

Returns ​

WithRequiredOption<CombinatorSchema<number>, R> — A combinator schema that resolves to number (integer).

Examples ​

ts
const args = {
  retries: integer({ min: 0, max: 10 })
}

Call Signature ​

ts
export declare function integer<const R extends boolean | undefined = boolean | undefined>(opts?: IntegerOptions & {
  required?: R;
}): WithUnrequiredOption<CombinatorSchema<number>, R>

Create an integer argument schema with optional range validation.

Only accepts integer values (no decimals).

Type Parameters ​

NameDescription
R extends boolean | undefined = boolean | undefinedThe type of required in the options, which the schema keeps when it may be false but not true, as for optional ? { required: false } : {}, so that a positional argument with it is optional.

Parameters ​

NameTypeDescription
optsIntegerOptions & { required?: R }Range options. (optional)

Returns ​

WithUnrequiredOption<CombinatorSchema<number>, R> — A combinator schema that resolves to number (integer).

Examples ​

ts
const args = {
  retries: integer({ min: 0, max: 10 })
}

Call Signature ​

ts
export declare function integer(opts?: IntegerOptions): CombinatorSchema<number>

Create an integer argument schema with optional range validation.

Only accepts integer values (no decimals).

Parameters ​

NameTypeDescription
optsIntegerOptionsRange options. (optional)

Returns ​

CombinatorSchema<number> — A combinator schema that resolves to number (integer).

Examples ​

ts
const args = {
  retries: integer({ min: 0, max: 10 })
}

Released under the MIT License.