Path<TFieldValues> not being inferred correctly #12930
Replies: 1 comment
|
This reproduces without the combobox implementation. For your fixed-name wrapper, a narrow assertion at this boundary works: // Keep: TFieldValues extends { memberId: number }
const memberName = 'memberId' as Path<TFieldValues>;Pass If you want the wrapper to support different field names, move the name into its props and let the caller's concrete form type check it: import type {
Control,
FieldErrors,
FieldPathByValue,
FieldValues,
} from 'react-hook-form';
type MemberInputProps<T extends FieldValues> = {
control: Control<T>;
errors: FieldErrors<T>;
name: FieldPathByValue<T, number>;
// Keep your queryResult prop here too.
};Inside // control/errors from useForm<{ memberId: number; title: string }>()
<MemberInput control={control} errors={errors} name="memberId" />
AI-assisted verification: a minimal reproducer with TypeScript 5.9.3 and RHF 7.90.0 reproduces the original error, compiles both approaches, and rejects string-valued/missing paths for the prop-based approach. This checks the type boundary, not your private combobox implementation. RHF's path type definitions show the conditional |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I've extracted out a component for a specific input that's used across several forms:
However, no matter what I try I'm getting this TS error:
Does anyone have any insight on why TS is unable to see that
memberIdis indeed a path in the form? I thought my use of generics addressed this, but it clearly doesn't.Edit: I should add that I don't think
RHFComboboxis relevant to this. Because even if I try to do something like:I get
All reactions