import { type AtomConfig, type SuperAtomType } from "../atom/atom"; import type { ValidatorFn } from "./validators"; /** * Widen literal types so that `formAtom("")` infers `FormAtom` * instead of `FormAtom<"">`, and `formAtom(0)` infers `FormAtom` * instead of `FormAtom<0>`. */ type Widen = T extends string ? string : T extends number ? number : T extends boolean ? boolean : T; /** Factory that returns the validators to run (called on every validate). */ export type ValidatorsFactory = () => ValidatorFn[]; /** * The callable interface returned by `formAtom()`. * * Extends `SuperAtomType` with form-specific members: errors, isValid, * dirty, validate(), and numeric helpers. */ export type FormAtom = SuperAtomType & { /** Run validators now (also marks the field dirty). */ validate(): string[]; /** Clear errors and mark the field pristine again. */ resetValidation(): void; readonly errors: string[]; readonly isValid: boolean; /** `true` after the first non-silent write or manual `validate()`. */ readonly dirty: boolean; readonly __isFormAtom__: true; toFloat(): number; toFloatString(): string; toValidNumber(): number; readonly name: "formAtom"; }; /** * Create a reactive form field atom. * * - No validation on mount (`dirty === false`, `errors === []`). * - After the first non-silent `set` / `update`, the field is dirty and * validators run automatically on every subsequent write. * - `validate()` forces validation (e.g. on submit) and marks dirty. * - `reset()` / `resetValidation()` clear dirty + errors. * * @example * const name = formAtom("", () => [isRequired, minLength(2)]); * name.dirty; // false * name.set("A"); // dirty=true, errors show * name.validate(); // force-run on submit */ export declare const formAtom: (initial: T, getValidators?: ValidatorsFactory>, config?: AtomConfig) => FormAtom>; export {}; //# sourceMappingURL=formAtom.d.ts.map