ciscoheat / sveltekit-superforms

Making SvelteKit forms a pleasure to use!
https://superforms.rocks
MIT License
2.13k stars 63 forks source link

Cannot access ZodValidation type #457

Closed benquan closed 1 month ago

benquan commented 1 month ago

Description I am coming from superforms V1 and have done most changes with no problems, but I used to reference a ZodValidation type that seems to be hidden now.

V1 Code was:

    import type { Message } from '$lib/superform';
    import type { z, AnyZodObject } from 'zod';
    import type { ZodValidation, FormPathLeaves } from 'sveltekit-superforms';
    import { formFieldProxy, type SuperForm } from 'sveltekit-superforms/client';

    type T = $$Generic<AnyZodObject>;
    export let form: SuperForm<ZodValidation<T>, Message>;
    export let field: FormPathLeaves<z.infer<T>>;
    export let title = field.toString();

    const { value, errors, constraints } = formFieldProxy(form, field);

I looked for ZodValidation in 'sveltekit-superforms/adapters' and the zod.js does have the exportable type, but adapters is only exposing zod and zodClient.

How should I change my reference?

ciscoheat commented 1 month ago

In v2, you don't use the Zod schema type, but instead the underlying data for the schema as the type parameter. Search the migration guide for Infer and it should hopefully be clear.