Skip to content

Cookbook: Handling Rails validation error types #215

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

Conversation

skryukov
Copy link
Contributor

I believe this should address #177

We could try to upstream the ability to set the errors type to the JS core, enabling something like:

const form = useForm<UserType, string[]>(...)

However, this approach is verbose, and I would still lean towards using global types 😅.

@pricci1
Copy link

pricci1 commented Apr 11, 2025

Considering that the code examples in the documentation and the generators pass the errors as arrays, maybe the global re-export should be part of the setup guide or even the inertia:install generator.

And also, maybe make the type be a string or a string array, though that would force everyone to check the runtime type

-    errors: Partial<Record<keyof TForm, string>>;
+    errors: Partial<Record<keyof TForm, string | string[]>>;

@skryukov
Copy link
Contributor Author

@pricci1 yeah, adding them to the generator makes sense. We can also include a link to the cookbook in the generated file so it’s easily understandable.

Copy link
Collaborator

@BrandonShar BrandonShar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this strategy of updating docs before trying a more brittle solution!

@BrandonShar BrandonShar merged commit cae8734 into inertiajs:master Apr 19, 2025
1 check passed
@skryukov skryukov deleted the cookbook/handling-validation-error-types branch April 19, 2025 09:20
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