Effect CommunityEC
Effect Community2y ago
7 replies
jedahu

Schema parsing with react-hook-form (PR)

Hello, thanks to whoever contributed the effect-ts react-hook-form resolver.

I've just written a PR for react-hook-form which will I think make it possible to truly parse to a different type by removing the TFieldValues constraint from TTransformedValues and I'd appreciate a sanity check. https://github.com/react-hook-form/react-hook-form/pull/11951

Looks like the resolver types will need to change to properly take advantage of it so that the schema's Encoded maps to TFieldValues and Type to TTransformedValues. The new resolver type would be:
export type Resolver = <I extends FieldValues, A, TContext>(
  schema: Schema.Schema<A, I>,
  config?: ParseOptions,
) => (
  values: FieldValues,
  _context: TContext | undefined,
  options: ResolverOptions<I>,
) => Promise<ResolverResult<A>>;


rather than the current types:
export type Resolver = <A extends FieldValues, I, TContext>(
  schema: Schema.Schema<A, I>,
  config?: ParseOptions,
) => (
  values: FieldValues,
  _context: TContext | undefined,
  options: ResolverOptions<A>,
) => Promise<ResolverResult<A>>;
Was this page helpful?