Skip to content

@jsvision/forms / AsyncValidator

Type Alias: AsyncValidator<T>

AsyncValidator<T> = (value, ctx) => Promise<string | null>

Defined in: types.ts:18

An opt-in asynchronous validator for a single field — the "is this username / email already taken?" round-trip class of check that a synchronous Zod schema cannot express.

It receives the field's raw editing value (coerce inside if you need a typed value) and an AbortSignal that is aborted when a newer change supersedes this run or the form is disposed — thread it into fetch so a stale request is cancelled. It resolves the error message to surface, or null for "no async error". A rejected promise is treated as "no async error"; if your validator can fail (e.g. the network is down), catch inside and return a message such as 'Could not verify' to surface that as an error.

Type Parameters

T

T

the field's raw editing value type.

Parameters

value

T

ctx

signal

AbortSignal

Returns

Promise<string | null>