Replies: 5 comments 8 replies
-
Hey, there is an issue with path being able to properly use generics right now. I believe the RHF team is working on it, see #7215 |
Beta Was this translation helpful? Give feedback.
-
Hi i have same problem. Do u have some info about resolve this issue? |
Beta Was this translation helpful? Give feedback.
-
What is the status on this issue? I came across the same problem and error messages and was wondering if a fix has been deployed yet. |
Beta Was this translation helpful? Give feedback.
-
The v8 is still in progress. You can already try the v8.0.0-alpha.4. No ETA for the stable release, tho For now, the only thing I was able to hack together is this: import type {
UseFormSetValue,
FieldValues,
FieldPath,
FieldPathValue
} from "react-hook-form";
import { useEffect } from "react";
type InputProps<
TFieldValues extends FieldValues,
TFieldName extends FieldPath<TFieldValues>
> = {
setValue: UseFormSetValue<TFieldValues>
name: TFieldName
};
const Input = <
TFieldValues extends FieldValues,
TFieldName extends FieldPath<TFieldValues>
>({
setValue,
name
}: InputProps<TFieldValues, TFieldName>) => {
setValue(name, "string" as FieldPathValue<TFieldValues, TFieldName>)
}; Here's a basic codesandbox |
Beta Was this translation helpful? Give feedback.
-
setValue(name, value as PathValue<T, Path>) |
Beta Was this translation helpful? Give feedback.
-
Hi, I was looking to create a wrapper function around setValue, but I can't figure out how to set up my generics to allow for setting a primitive value.
Argument of type 'string' is not assignable to parameter of type 'UnpackNestedValue<PathValue<T, Path<T>>>'.ts(2345)
Here's a super simple example of what I'm attempting to do: https://codesandbox.io/s/flamboyant-frog-dv8v1?file=/src/App.tsx
Is there a way to specify via generics that all values are string? Or for it to look up the value by the path?
Beta Was this translation helpful? Give feedback.
All reactions