@mitcsutt/kiln-forms
Version:
Kiln forms: typed React forms on TanStack Form, in component or JSON schema mode, rendered through kiln-ui
28 lines (27 loc) • 1.13 kB
TypeScript
import type { DeepKeys } from '@tanstack/react-form';
import { type AnyKitForm } from './formRuntime.js';
/** Server-side errors: one form-level message and/or messages per field path. */
export interface ServerErrors<T = unknown> {
form?: string;
fields?: Partial<Record<DeepKeys<T>, string>>;
}
/**
* Throw from `onSubmit` to map server errors onto the form (§5.5): field errors go to each
* field's `onServer` slot (cleared on its next change), the form error to the form's.
*/
export declare class FormSubmitError<T = unknown> extends Error {
readonly errors: ServerErrors<T>;
constructor(errors: ServerErrors<T>, message?: string);
}
type ValuesOfForm<A> = A extends {
state: {
values: infer V;
};
} ? V : never;
/**
* Applies server errors: field messages → each field's `onServer` slot (source `field`, so other
* fields' edits don't clear them); the form message (plus any message for a path with no field)
* → the form's `onServer` slot.
*/
export declare function applyServerErrors<A extends AnyKitForm>(target: A, errors: ServerErrors<ValuesOfForm<A>>): void;
export {};