Possible issue with UnpackNestedValue
See original GitHub issueDescribe the bug I’m sorry if this is a bug/mistake on my side. I’m still catching up with TS and react-hook-form Seems that certain types are not handled well with UnpackNestedValue
To Reproduce Steps to reproduce the behavior:
import { useForm } from "react-hook-form";
import "./styles.css";
const testFunction = (query: Record<string, string | undefined | null>): void => {
console.log(query)
};
export const Second = <T extends Record<string, string | undefined | null>>(): void => {
const form = useForm<T>();
const values = form.watch();
testFunction(values)
}
Error:
Argument of type 'UnpackNestedValue<T>' is not assignable to parameter of type 'Record<string, string | null | undefined>'.
Type 'NonUndefined<T> | (NonUndefined<T> extends Date | FileList ? T : NonUndefined<T> extends Record<string, unknown> ? { [K in keyof T]: UnpackNestedValue<...>; } : T)' is not assignable to type 'Record<string, string | null | undefined>'.
Type 'NonUndefined<T> extends Date | FileList ? T : NonUndefined<T> extends Record<string, unknown> ? { [K in keyof T]: UnpackNestedValue<T[K]>; } : T' is not assignable to type 'Record<string, string | null | undefined>'.
Type 'T | (NonUndefined<T> extends Record<string, unknown> ? { [K in keyof T]: UnpackNestedValue<T[K]>; } : T)' is not assignable to type 'Record<string, string | null | undefined>'.
Type 'NonUndefined<T> extends Record<string, unknown> ? { [K in keyof T]: UnpackNestedValue<T[K]>; } : T' is not assignable to type 'Record<string, string | null | undefined>'.
Type 'T | { [K in keyof T]: UnpackNestedValue<T[K]>; }' is not assignable to type 'Record<string, string | null | undefined>'.
Type '{ [K in keyof T]: UnpackNestedValue<T[K]>; }' is not assignable to type 'Record<string, string | null | undefined>'.
Type 'UnpackNestedValue<T[K]>' is not assignable to type 'string | null | undefined'.
Type 'Record<string, unknown> | unknown[] | (NonUndefined<T[K]> extends Date | FileList ? T[K] : NonUndefined<T[K]> extends Record<string, unknown> ? { [K in keyof T[K]]: UnpackNestedValue<...>; } : T[K])' is not assignable to type 'string | null | undefined'.
Type 'Record<string, unknown>' is not assignable to type 'string'.
Type 'UnpackNestedValue<T[K]>' is not assignable to type 'string'.
Type 'Record<string, unknown> | unknown[] | (NonUndefined<T[K]> extends Date | FileList ? T[K] : NonUndefined<T[K]> extends Record<string, unknown> ? { [K in keyof T[K]]: UnpackNestedValue<...>; } : T[K])' is not assignable to type 'string'.
Type 'Record<string, unknown>' is not assignable to type 'string'.
Expected behavior
if I tweak UnpackNestedValue a bit error is gone.
export declare type UnpackNestedValue<T> = NonUndefined<T> extends NestedValue<infer U>
? U
: NonUndefined<T> extends Date | FileList
? T
: T extends Record<string, unknown> // change NonUndefined<T> to T
? {
[K in keyof T]: UnpackNestedValue<T[K]>;
}
: T;
Additional context issue arrived with 6.x react-hook-form version
Issue Analytics
- State:
- Created 3 years ago
- Reactions:8
- Comments:15 (3 by maintainers)
Top Results From Across the Web
React Hook Form Type Issue with EditorState ...
I am currently wondering how the UnpackNestedValues Type works for objects like Files (Blob) or an EditorState (DraftJS).
Read more >TS Support | React Hook Form - Simple React forms validation
This type will return union with all available paths that match the passed value. Copy. function Field< TFieldValues extends FieldValues, TPath extends ...
Read more >defaultValues-typing-UnpackNestedValue - CodeSandbox
VS Code's tsserver was deleted by another application such as a misbehaving virus detection tool. Please reinstall VS Code. Manage Extension.
Read more >How to create reusable form components with React Hook ...
When we attempt to do this, we'll encounter an issue. ... Each form will likely have different validation rules and errors. Now what?...
Read more >react-hook-form - Awesome JS
promise will only be resolved once during useForm() call; It's possible to ... fix #9571 validation issue with unregister input with valueAsNumber (#9572)...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
+1 to reopen this!
I’m using
^7.20.2
and facing the same error, can this please be reopened?