Skip to content

How to narrow down the type of register (UseFormRegister) within a form which uses a discriminated union as its FieldValues. #12975

Discussion options

You must be logged in to vote

I finally managed to find a semi-decent solution, and I am posting it here for future reference and in case someone else finds this. But I am honestly kind of shocked something as common as this requires so much time digging through Discord threads, online forums and issues but no viable solution to be found. Do people only build linear forms these days, or maybe I am missing something obvious. And if you think tanstack form solves this issue, think again.

import "./styles.css";
import { useForm, UseFormReturn } from "react-hook-form";
import { z } from "zod";
import { InputSelect } from "./Select";
import { InputText } from "./Text";
import { zodResolver } from "@hookform/resolvers/zod";

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by virtuallyunknown
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