Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect types: Form should extend RequestPayload #1626

Closed
wants to merge 1 commit into from
Closed

Incorrect types: Form should extend RequestPayload #1626

wants to merge 1 commit into from

Conversation

Bloemendaal
Copy link
Contributor

Resubmission of #1479 since this is still a problem for us.

I'm getting the following errors:

TS2344: Type 'MyFormData' does not satisfy the constraint 'Record<string, unknown>'.
Index signature for type 'string' is missing in type 'MyFormData'.

This PR uses the RequestPayload type which is also used by the router to validate the data.

@Bloemendaal Bloemendaal changed the title Form should extend RequestPayload Incorrect types: Form should extend RequestPayload Jul 28, 2023
@jessarcher
Copy link
Member

Hey @Bloemendaal,

Where are you seeing this error? I can't figure out how to replicate it to confirm the issue and solution.

Can you please provide a minimal reproduction?

@Bloemendaal
Copy link
Contributor Author

Bloemendaal commented Aug 9, 2023

Hi @jessarcher! Thanks voor looking into this. Here's an snippet from our codebase:

interface FormData {
    fullName: string;
    phone: string;
    email: string;
}

export interface BasicInfoProps extends SharedProps {
    fullName: string;
    phone: string;
    email: string;
}

const BasicInfo = ({
    nextRouteUri,
    errors,
    fullName,
    phone,
    email,
}: BasicInfoProps) => {
    const { data, setData, post, processing } = useForm<FormData>('basicInfo', {
        fullName: fullName || '',
        phone: phone || '',
        email: email || '',
    });

    // ...

    return <div>Hello {data.fullName}!</div>
};

This gives the following error:
Scherm­afbeelding 2023-08-09 om 08 41 16

@reinink
Copy link
Member

reinink commented Aug 17, 2023

Hey @Bloemendaal thanks so much for submitting this fix, but I think we're going to go with the solution in #1649 instead — which should also solve this issue for you 👍

@reinink reinink closed this Aug 17, 2023
@Bloemendaal Bloemendaal deleted the form-with-requestpayload branch August 17, 2023 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants