control type incompatibility in v6.5.0-6.8.4
See original GitHub issueDescribe the bug
When specifying types for controls via T extends Record<string, any>
typing errors are raised that exist from versions 6.5.0 through to 6.8.4. I’ve demonstrated the issue in sandboxes below for the error as well as the working version in 6.4.1.
Note: that it doesn’t seem to impact the execution on codesandbox, but under certain TypeScript configurations will break the build.
Type 'Control<T>' is not assignable to type 'Control<Record<string, any>> | undefined'.
Type 'Control<T>' is not assignable to type 'Control<Record<string, any>>'.
Type 'Control<T>' is not assignable to type '{ removeFieldEventListener: (field: Field, forceDelete?: boolean | undefined) => void; mode: Readonly<{ isOnBlur: boolean; isOnSubmit: boolean; isOnChange: boolean; isOnAll: boolean; isOnTouch: boolean; }>; ... 19 more ...; renderWatchedInputs: (name: string, found?: boolean | undefined) => void; }'.
Types of property 'updateFormState' are incompatible.
Type '(args?: Partial<FormState<T>> | undefined) => void' is not assignable to type '(args?: Partial<FormState<Record<string, any>>> | undefined) => void'.
Types of parameters 'args' and 'args' are incompatible.
Type 'Partial<FormState<Record<string, any>>> | undefined' is not assignable to type 'Partial<FormState<T>> | undefined'.
Type 'Partial<FormState<Record<string, any>>>' is not assignable to type 'Partial<FormState<T>>'.
Types of property 'dirtyFields' are incompatible.
Type 'DeepMap<Record<string, any>, true> | undefined' is not assignable to type 'DeepMap<T, true> | undefined'.
Type 'DeepMap<Record<string, any>, true>' is not assignable to type 'DeepMap<T, true>'.ts(2322)
controller.d.ts(20, 5): The expected type comes from property 'control' which is declared here on type '(IntrinsicAttributes & { as: "textarea" | "input" | "select" | FunctionComponent<any> | ComponentClass<any, any> | ReactElement<...>; render?: undefined; } & { ...; } & Pick<...>) | (IntrinsicAttributes & ... 2 more ... & Pick<...>)'
Codesandbox link (Required) Bug 6.8.4 - https://codesandbox.io/s/react-hook-form-control-type-issue-yj7kz?file=/src/TextField.tsx Working 6.4.1 - https://codesandbox.io/s/react-hook-form-control-type-issue-forked-fmpuo?file=/src/TextField.tsx
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
No results found
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
Thanks @bluebill1049 👏
sweet closing this issue, will release the patch soon 👍