@abyrd9/zod-form-data
Version:
Type-safe Zod v4 utilities to flatten and unflatten data, parse FormData, and collect schema-aligned errors.
31 lines • 1.18 kB
TypeScript
import * as z4 from "zod/v4/core";
import type { NestedFieldErrors } from "./flatten-zod-form-errors";
import type { DeepPartial } from "./deep-partial";
import type { FlattenedPaths } from "./schema-paths";
type MetaKeys = "form" | "global";
type FlattenedErrorsWithMeta<T extends z4.$ZodType> = Partial<Record<FlattenedPaths<T> | MetaKeys, string>>;
export type ParseErrors<T extends z4.$ZodType> = {
form?: string;
global?: string;
fields?: DeepPartial<NestedFieldErrors<T>>;
flattened?: FlattenedErrorsWithMeta<T>;
};
export type ParseSuccess<T extends z4.$ZodType> = {
success: true;
data: z4.output<T>;
errors?: undefined;
};
export type ParseFailure<T extends z4.$ZodType> = {
success: false;
data?: undefined;
errors: ParseErrors<T>;
};
export type ParseResult<T extends z4.$ZodType> = ParseSuccess<T> | ParseFailure<T>;
export declare const parseFormData: <T extends z4.$ZodType>(form: FormData, { schema, }: {
schema: T;
}) => ParseResult<T>;
export declare const parseData: <T extends z4.$ZodType>(data: unknown, { schema, }: {
schema: T;
}) => ParseResult<T>;
export {};
//# sourceMappingURL=parse-zod-form-data.d.ts.map