Skip to content

Function: string() ​

Call Signature ​

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

Create a string argument schema with optional validation.

Type Parameters ​

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

Parameters ​

NameTypeDescription
optsStringOptions & { required: R }Validation options.

Returns ​

WithRequiredOption<CombinatorSchema<string>, R> — A combinator schema that resolves to string.

Examples ​

ts
const args = {
  name: string({ minLength: 1, maxLength: 50 })
}

Call Signature ​

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

Create a string argument schema with optional validation.

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
optsStringOptions & { required?: R }Validation options. (optional)

Returns ​

WithUnrequiredOption<CombinatorSchema<string>, R> — A combinator schema that resolves to string.

Examples ​

ts
const args = {
  name: string({ minLength: 1, maxLength: 50 })
}

Call Signature ​

ts
export declare function string(opts?: StringOptions): CombinatorSchema<string>

Create a string argument schema with optional validation.

Parameters ​

NameTypeDescription
optsStringOptionsValidation options. (optional)

Returns ​

CombinatorSchema<string> — A combinator schema that resolves to string.

Examples ​

ts
const args = {
  name: string({ minLength: 1, maxLength: 50 })
}

Released under the MIT License.