-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
[suggestion] Implicit Inference of Form Schema in getValidatedFormData
and validateFormData
#55
Comments
@MonsterDeveloper No real reason, I actually didn't even think about using the resolver type to resolve it because I relied on the schemas themselves. Would love this PR |
Played a bit with the types, turns out inferring the resolver output type is not possible as the resolver doesn't expose its schema: export type Resolver = <T extends z.Schema<any, any>>(schema: T, schemaOptions?: Partial<z.ParseParams>, factoryOptions?: {
// ...
// no `T` here
}) => <TFieldValues extends FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>; So when we're doing |
Does it return the data as typed? If so there would be a way to do it 🤔 |
That's the thing — it doesn't. So no way of getting the type of data passed to the resolver function. Not now, at least. |
@MonsterDeveloper let me look into this, I have an idea |
I've looked a bit at the source code of the // No generics for inference
export const arktypeResolver: Resolver =
(schema, _schemaOptions, resolverOptions = {}) =>
(values, _, options) => { // Return type is inferred
export function yupResolver<TFieldValues extends FieldValues>(
schema:
| Yup.ObjectSchema<TFieldValues>
| ReturnType<typeof Yup.lazy<Yup.ObjectSchema<TFieldValues>>>,
schemaOptions: Parameters<(typeof schema)['validate']>[1] = {},
resolverOptions: {
// skipped
): Resolver<Yup.InferType<typeof schema>> { For While we could implement inferring resolver's |
In fact, not even react-hook-form itself is inferring the type of the form data from the resolver, but only from the explicit generic or from default values. |
Hello!
I am currently exploring the
remix-hook-form
library and observed that when utilizinggetValidatedFormData
andvalidateFormData
, the form schema needs to be explicitly included in the generic.Considering that both functions require a resolver, it seems feasible to allow automatic inference of the
T
type from the resolver.I could open a PR to introduce this enhancement. But before that, I would appreciate some clarification if there is a specific reason for not implementing this feature that I might be unaware of.
The text was updated successfully, but these errors were encountered: