Skip to content
Discussion options

You must be logged in to vote

Ok si this was my own fault. I just must use (and supply) FieldName generic type.

export type TextFieldElementProps<
  FormValues extends FieldValues,
  FieldName extends FieldPath<FormValues> = FieldPath<FormValues>
> = TextFieldProps & {
  rules?: ControllerProps<FormValues, FieldName >["rules"];
};

then I must create TextFieldElement component like this

<TextFieldElement<MyFormValues, "myFieldName">
  fieldName="myFieldName"
  rules={{
    validate: (value) => {
      // now typescript knows the specific value for the field
    },
  }}
/>

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by waxcage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant