Skip to content

Form Data type is schema's inferred output type, instead of the input type #628

@gyenabubakar

Description

@gyenabubakar
  • Before posting an issue, read the FAQ and search the previous issues.

Description & Reproduction

Check this code (don't change branches): https://github.com/gyenabubakar/superforms-infinite-id-warnings/tree/valibot-incorrect-input-types

Inside src/routes/+page.svelte, the inferred type of formData is:

SuperFormData<{
    email?: string | undefined;
    phone?: string | undefined;
    password: string;
}>

The type of the phone property is incorrect. It's supposed to be:

SuperFormData<{
    email?: string | undefined;
    phone?: {
        code: <string union>;
        number: string;
    };
    password: string;
}>

I .transform the phone object above into a string using libphonenumber-js. So, the transform should only happen after the form data passes the schema check. But in this case, it seems the Superforms adapter for Valibot infers the output type of objects instead of the input type. This problem seems to exist for the Zod adapter as well.

Does Superforms not support nested objects?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions