Skip to content

FieldTypeDef ​

A field type, as defineFieldType takes it.

Generics ​

Definition ​

  • FieldTypeDef
    • kind ValueKind | KindOf: the kind of its value, or a function of the field with its props parsed
    • itemKind ValueKind | KindOf: optional, the kind of each item for kind array
    • props TProps: optional, the extra keys it takes
    • schema (field: FieldWithProps, ctx: BuildContext) => AnySchema: the schema of its value. Required unless its kind is none
    • defaultRules readonly JsonRule[]: optional, rules every field of the type gets
    • required (message: string) => AnyAction | null: optional, replaces the kind's required check
    • finalize (field: FieldWithProps) => AnyAction | undefined: optional, runs after every rule
    • container boolean: optional, true for a type whose value holds other fields
    • meta FieldTypeMeta: optional

Explanation ​

See custom field types.

FieldTypeMeta ​

  • FieldTypeMeta
    • label string
    • description string: optional

FieldWithProps ​

ts
type FieldWithProps<TProps> = JsonField & InferOutput<TProps>

A field with its type's props parsed and typed.

KindOf ​

A kind or itemKind that depends on the props: a select with number options has kind number.

ts
type KindOf<TProps> = (field: FieldWithProps<TProps>) => ValueKind

BuildContext ​

  • BuildContext
    • path DefinitionPath: where the field is in the definition
    • buildFields (fields: readonly JsonField[], path: DefinitionPath) => AnyObjectSchema: checks and builds child fields
    • buildField (field: JsonField, path: DefinitionPath) => AnySchema: checks and builds the field of a list's items

AnySchema, AnyAction, AnyObjectSchema ​

The Valibot schema and action types a field type works with: any schema, any action, and any object schema.

Functions ​