Skip to content

defineFieldType ​

Defines a field type. It returns the type unchanged, typed so that schema() and kind get the field with its props parsed.

ts
const type = defineFieldType<TProps>(def)

Generics ​

Parameters ​

Explanation ​

Register the type with createSchemaBuilder's fieldTypes option, under the name definitions use in type.

Returns ​

Example ​

ts
const tags = defineFieldType({
  kind: 'array',
  itemKind: 'string',
  props: v.object({ max: v.optional(v.number()) }),
  schema: (field) =>
    v.pipe(v.array(v.string()), v.maxLength(field.max ?? 10)), // field.max is typed
  meta: { label: 'Tags', description: 'A list of short texts' },
})

const builder = createSchemaBuilder({ fieldTypes: { tags } })

Guides ​

Types ​