Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue: Type generics do not work well with TS Unions #11956

Open
1 task done
keithrz opened this issue May 31, 2024 · 3 comments
Open
1 task done

issue: Type generics do not work well with TS Unions #11956

keithrz opened this issue May 31, 2024 · 3 comments
Labels
TS Typescript related issues

Comments

@keithrz
Copy link

keithrz commented May 31, 2024

Version Number

7.51.1

Codesandbox/Expo snack

https://codesandbox.io/p/sandbox/loving-golick-swltg4

Steps to reproduce

  1. Go to 'App.tsx' in the code sandbox
  2. Hover your mouse over the TypeScript error for "control"
  3. You should see the following TS error:
Type 'Control<FormValues<Product>>' is not assignable to type 'Control<FormValues<Product | Discount>>'.
  Types of property 'register' are incompatible.
    Type 'UseFormRegister<FormValues<Product>>' is not assignable to type 'UseFormRegister<FormValues<Product | Discount>>'.
      Type 'FormValues<Product | Discount>' is not assignable to type 'FormValues<Product>'.typescript(2322)
InternalField.tsx(14, 3): The expected type comes from property 'control' which is declared here on type 'IntrinsicAttributes & { control: Control<FormValues<Product | Discount>>; trigger: UseFormTrigger<FormValues<Product | Discount>>; }'
(property) control: Control<FormValues<Product | Discount>>

Expected behaviour

No TS error, because Product is part of the TS Union Product | Discount

What browsers are you seeing the problem on?

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@paynecodes
Copy link

paynecodes commented May 31, 2024

I'm seeing this issue as well on [email protected]. Thank you for reporting.

Reverting 7.50.1 works for now.

@keithrz
Copy link
Author

keithrz commented May 31, 2024

Thanks for the response! I am not seeing the error go away after bumping my local version down to 7.50.1

This prompted me to check the version I have in the code sandbox, and the version there is actually 7.4.1, so as far as I can tell, it looks like this issue was introduced awhile ago.

I forked the sandbox and updated the version to the latest (7.51.5), and the issue still occurs. Changing the sandbox to version 7.50.1 does not change behavior, either

@bluebill1049 bluebill1049 added the TS Typescript related issues label Jun 1, 2024
@joaopedrodcf
Copy link

I was on "react-hook-form": "7.51.4" without errors and after upgrading to "react-hook-form": "7.51.5" the typing errors started appearing 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TS Typescript related issues
Projects
None yet
Development

No branches or pull requests

4 participants