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
TPropsextends AnyObjectSchema
Parameters
defFieldTypeDef<TProps>
Explanation
Register the type with createSchemaBuilder's fieldTypes option, under the name definitions use in type.
Returns
typeFieldTypeDef<TProps>
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 } })