Skip to main content

Class: VObject<Type, Fields, IsOptional, FieldPaths>

values.VObject

The type of the v.object() validator.

Type parameters

NameType
TypeType
Fieldsextends Record<string, GenericValidator>
IsOptionalextends OptionalProperty = "required"
FieldPathsextends string = { [Property in keyof Fields]: JoinFieldPaths<Property & string, Fields[Property]["fieldPaths"]> | Property }[keyof Fields] & string

Hierarchy

  • BaseValidator<Type, IsOptional, FieldPaths>

    VObject

Constructors

constructor

new VObject<Type, Fields, IsOptional, FieldPaths>(«destructured»)

Usually you'd use v.object({ ... }) instead.

Type parameters

NameType
TypeType
Fieldsextends Record<string, GenericValidator>
IsOptionalextends OptionalProperty = "required"
FieldPathsextends string = { [Property in string | number | symbol]: Property | `${Property & string}.${Fields[Property]["fieldPaths"]}` }[keyof Fields] & string

Parameters

NameType
«destructured»Object
› isOptionalIsOptional
› fieldsFields

Overrides

BaseValidator&lt;Type, IsOptional, FieldPaths&gt;.constructor

Defined in

values/validators.ts:289

Properties

type

Readonly type: Type

Only for TypeScript, the TS type of the JS values validated by this validator.

Inherited from

BaseValidator.type

Defined in

values/validators.ts:22


fieldPaths

Readonly fieldPaths: FieldPaths

Only for TypeScript, if this an Object validator, then this is the TS type of its property names.

Inherited from

BaseValidator.fieldPaths

Defined in

values/validators.ts:27


isOptional

Readonly isOptional: IsOptional

Whether this is an optional Object property value validator.

Inherited from

BaseValidator.isOptional

Defined in

values/validators.ts:32


isConvexValidator

Readonly isConvexValidator: true

Always "true".

Inherited from

BaseValidator.isConvexValidator

Defined in

values/validators.ts:37


fields

Readonly fields: Fields

An object with the validator for each property.

Defined in

values/validators.ts:279


kind

Readonly kind: "object"

The kind of validator, "object".

Defined in

values/validators.ts:284

Methods

omit

omit<K>(...fields): VObject<Expand<Omit<Type, K>>, Expand<Omit<Fields, K>>, IsOptional, { [Property in string | number | symbol]: Property | `${Property & string}.${Expand<Omit<Fields, K>>[Property]["fieldPaths"]}` }[keyof Expand<Omit<Fields, K>>] & string>

Create a new VObject with the specified fields omitted.

Type parameters

NameType
Kextends string

Parameters

NameTypeDescription
...fieldsK[]The field names to omit from this VObject.

Returns

VObject<Expand<Omit<Type, K>>, Expand<Omit<Fields, K>>, IsOptional, { [Property in string | number | symbol]: Property | `${Property & string}.${Expand<Omit<Fields, K>>[Property]["fieldPaths"]}` }[keyof Expand<Omit<Fields, K>>] & string>

Defined in

values/validators.ts:331


pick

pick<K>(...fields): VObject<Expand<Pick<Type, Extract<keyof Type, K>>>, Expand<Pick<Fields, K>>, IsOptional, { [Property in string | number | symbol]: Property | `${Property & string}.${Expand<Pick<Fields, K>>[Property]["fieldPaths"]}` }[keyof Expand<Pick<Fields, K>>] & string>

Create a new VObject with only the specified fields.

Type parameters

NameType
Kextends string

Parameters

NameTypeDescription
...fieldsK[]The field names to pick from this VObject.

Returns

VObject<Expand<Pick<Type, Extract<keyof Type, K>>>, Expand<Pick<Fields, K>>, IsOptional, { [Property in string | number | symbol]: Property | `${Property & string}.${Expand<Pick<Fields, K>>[Property]["fieldPaths"]}` }[keyof Expand<Pick<Fields, K>>] & string>

Defined in

values/validators.ts:348


partial

partial(): VObject<{ [K in string | number | symbol]?: Type[K] }, { [K in string | number | symbol]: VOptional<Fields[K]> }, IsOptional, { [Property in string | number | symbol]: Property | `${Property & string}.${{ [K in string | number | symbol]: VOptional<Fields[K]> }[Property]["fieldPaths"]}` }[keyof Fields] & string>

Create a new VObject with all fields marked as optional.

Returns

VObject<{ [K in string | number | symbol]?: Type[K] }, { [K in string | number | symbol]: VOptional<Fields[K]> }, IsOptional, { [Property in string | number | symbol]: Property | `${Property & string}.${{ [K in string | number | symbol]: VOptional<Fields[K]> }[Property]["fieldPaths"]}` }[keyof Fields] & string>

Defined in

values/validators.ts:368


extend

extend<NewFields>(fields): VObject<Expand<Type & ObjectType<NewFields>>, Expand<Fields & NewFields>, IsOptional, { [Property in string | number | symbol]: Property | `${Property & string}.${Expand<Fields & NewFields>[Property]["fieldPaths"]}` }[keyof Expand<Fields & NewFields>] & string>

Create a new VObject with additional fields merged in.

Type parameters

NameType
NewFieldsextends Record<string, GenericValidator>

Parameters

NameTypeDescription
fieldsNewFieldsAn object with additional validators to merge into this VObject.

Returns

VObject<Expand<Type & ObjectType<NewFields>>, Expand<Fields & NewFields>, IsOptional, { [Property in string | number | symbol]: Property | `${Property & string}.${Expand<Fields & NewFields>[Property]["fieldPaths"]}` }[keyof Expand<Fields & NewFields>] & string>

Defined in

values/validators.ts:389