[TypeScript] Add generic type parameters to getSimpleValidationResolver#11150
Merged
slax57 merged 2 commits intomarmelab:masterfrom Feb 9, 2026
Merged
Conversation
Contributor
Author
|
Issue Ref #11149 |
eli-rlima
approved these changes
Feb 5, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds generic type parameters to the getSimpleValidationResolver function and ValidateForm type to enable better TypeScript support for strongly-typed form validation. This allows developers to specify the exact shape of their form values when creating validation resolvers, ensuring type safety and compatibility with react-hook-form.
Changes:
- Added generic type parameters
<TFieldValues, TErrors>togetSimpleValidationResolver - Updated
ValidateFormtype to accept genericTFieldValuesparameter - Updated JSDoc example to demonstrate typed validation function usage
- Added type assertions for return values to support the generic types
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/ra-core/src/form/validation/getSimpleValidationResolver.ts
Outdated
Show resolved
Hide resolved
packages/ra-core/src/form/validation/getSimpleValidationResolver.ts
Outdated
Show resolved
Hide resolved
packages/ra-core/src/form/validation/getSimpleValidationResolver.ts
Outdated
Show resolved
Hide resolved
slax57
requested changes
Feb 6, 2026
Comment on lines
51
to
52
| values: {} as TFieldValues, | ||
| errors: transformedErrors as TErrors, |
Contributor
There was a problem hiding this comment.
Looks like you are missing some return paths (e.g. line 34 or 46)
Contributor
Author
There was a problem hiding this comment.
Truly, thanks!
Now it is solved:

Commit: 19d910a
export const N = () => {
// 1. Define the interface
interface FormValues {
name: string;
email: string;
age: number;
}
// 2. Define the validator
const validateA = (values: FormValues) => {
const errors: Partial<Record<keyof FormValues, string>> = {};
if (!values.name) errors.name = 'Required';
if (!values.email) errors.email = 'Required';
return errors;
};
// 3. Create the resolver with the generic type
const resolver = getSimpleValidationResolver<FormValues>(validateA);
return null;
};569ec96 to
19d910a
Compare
slax57
reviewed
Feb 9, 2026
packages/ra-core/src/form/validation/getSimpleValidationResolver.ts
Outdated
Show resolved
Hide resolved
packages/ra-core/src/form/validation/getSimpleValidationResolver.ts
Outdated
Show resolved
Hide resolved
packages/ra-core/src/form/validation/getSimpleValidationResolver.ts
Outdated
Show resolved
Hide resolved
packages/ra-core/src/form/validation/getSimpleValidationResolver.ts
Outdated
Show resolved
Hide resolved
packages/ra-core/src/form/validation/getSimpleValidationResolver.ts
Outdated
Show resolved
Hide resolved
slax57
approved these changes
Feb 9, 2026
getSimpleValidationResolver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Problem
Fix #11149
The
getSimpleValidationResolverfunction does not currently accept generic type parameters. This prevents developers from strictly typing their form values and validation functions.When using
getSimpleValidationResolverwith a specific TypeScript interface, it defaults toFieldValues, causing type mismatches and TypeScript errors when passing the generated resolver touseFormor React Admin form components (like<SimpleForm>).Solution
I have updated
getSimpleValidationResolverand theValidateFormtype definition to accept a generic type parameter<TFormValues extends FieldValues = FieldValues>.This change allows consumers to specify the exact shape of their form values when creating a validation resolver, ensuring type safety and compatibility with
react-hook-form.How To Test
You can verify the fix by creating a strongly typed form and validation function. The following code should no longer produce TypeScript errors: