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: API Breakage on FieldErrors #8619

Closed
1 task done
craigmcc opened this issue Jul 2, 2022 · 11 comments
Closed
1 task done

issue: API Breakage on FieldErrors #8619

craigmcc opened this issue Jul 2, 2022 · 11 comments
Labels
TS Typescript related issues

Comments

@craigmcc
Copy link

craigmcc commented Jul 2, 2022

Version Number

7.33.1

Codesandbox/Expo snack

Compile error, so no code sandbox is available.

Steps to reproduce

I am building out a set of Typescript React components (based on react-hook-form and react-bootstrap). The source code for this library is at:

https://github.com/craigmcc/shared-react

With react-hook-form 7.30.0, everything was fine.
With react-hook-form 7.33.1, I get compile errors trying to build the library (see the "Relevant Log Output" section below).

It looks like changes to the FieldErrors definition is what is triggering this.

TO REPRODUCE:

  • Download the GItHub module mentioned above.
  • Run "npm install" to install the listed dependencies.
  • Run "npm install react-hook-form@7.33.1" to get the version that causes the problem.
  • Run "npm build" and see the compile errors (shown in the "Relevant log output" section below).

Expected behaviour

No compile errors.

What browsers are you seeing the problem on?

Chrome

Relevant log output

COMPILE OUTPUT:
==============

MacBook-Pro:shared-react craigmcc$ npm run build

> @craigmcc/shared-react@1.2.1 build
> tsc -p .

src/SelectField/SelectField.tsx:71:17 - error TS2322: Type 'Merge<FieldError, FieldErrorsImpl<DeepRequired<any>>> | undefined' is not assignable to type 'ReactNode'.
  Type 'Merge<FieldError, FieldErrorsImpl<DeepRequired<any>>>' is not assignable to type 'ReactNode'.
    Type 'Merge<FieldError, FieldErrorsImpl<DeepRequired<any>>>' is missing the following properties from type 'ReactPortal': key, children, type, props

71                 {props.errors[props.name]?.message}
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  node_modules/@types/react/index.d.ts:1374:9
    1374         children?: ReactNode | undefined;
                 ~~~~~~~~
    The expected type comes from property 'children' which is declared here on type 'IntrinsicAttributes & Omit<Pick<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof HTMLAttributes<...>> & { ...; }, BsPrefixProps<...> & FeedbackProps> & BsPrefixProps<...> & FeedbackProps & { ...; }'

src/TextField/TextField.tsx:66:17 - error TS2322: Type 'Merge<FieldError, FieldErrorsImpl<DeepRequired<any>>> | undefined' is not assignable to type 'ReactNode'.

66                 {props.errors[props.name]?.message}
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  node_modules/@types/react/index.d.ts:1374:9
    1374         children?: ReactNode | undefined;
                 ~~~~~~~~
    The expected type comes from property 'children' which is declared here on type 'IntrinsicAttributes & Omit<Pick<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof HTMLAttributes<...>> & { ...; }, BsPrefixProps<...> & FeedbackProps> & BsPrefixProps<...> & FeedbackProps & { ...; }'


Found 2 errors in 2 files.

Errors  Files
     1  src/SelectField/SelectField.tsx:71
     1  src/TextField/TextField.tsx:66

Code of Conduct

  • I agree to follow this project's Code of Conduct
@bluebill1049 bluebill1049 added the status: need more detail Please follow our issue template. label Jul 2, 2022
@bluebill1049
Copy link
Member

please follow the issue template by providing a codesandbox to reproduce this issue then will reopen and look into it.

@craigmcc
Copy link
Author

craigmcc commented Jul 2, 2022

Codesandbox link: https://codesandbox.io/s/goofy-fast-vdssvf

Although the app runs in the sandbox (it fails for me locally), if you open src/TextField.tsx and src/MyForm.tsx you will see the highlighted errors.

Change the react-hook-form dependency to 7.32 and it makes those errors go away.

@shamilovtim
Copy link

Same problem. The typedef has some sort of breaking change where it no longer passes a string.

@quadrifolia
Copy link

quadrifolia commented Jul 4, 2022

Same problem. Something is off with the typedef…
error occurs on: errors?.field?.type === 'required'

`TS2367: This condition will always return 'false' since the types 'Merge<FieldError, FieldErrorsImpl<DeepRequired>> | undefined' and 'string' have no overlap.

@bluebill1049 bluebill1049 reopened this Jul 4, 2022
@bluebill1049 bluebill1049 added status: under investigation aware of this issue and pending for investigation TS Typescript related issues and removed status: need more detail Please follow our issue template. labels Jul 4, 2022
@bluebill1049
Copy link
Member

bluebill1049 commented Jul 4, 2022

Same problem. Something is off with the typedef… error occurs on: errors?.field?.type === 'required'

`TS2367: This condition will always return 'false' since the types 'Merge<FieldError, FieldErrorsImpl> | undefined' and 'string' have no overlap.

  • can you provide a codesandbox to reproduce the issue or supply a test case to demonstrate the issue?
  • also which TS version are you running?
  • Please don't dump an entire project, it seriously does not help with my limited free time to investigate the issue.

(Below is a quick test, i may miss something here)

Screen Shot 2022-07-04 at 6 02 15 pm

@bluebill1049 bluebill1049 added the status: need more detail Please follow our issue template. label Jul 4, 2022
@quadrifolia
Copy link

quadrifolia commented Jul 4, 2022

happens only with useFormContext, not with useForm –> https://codesandbox.io/s/sad-allen-tgj0ho?file=/src/FormField.tsx

@quadrifolia
Copy link

going back in the releases…

7.33.0 different errors:
Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'FieldError | Merge<FieldError, FieldErrors>'.

7.32.2: all good, no errors

@bluebill1049
Copy link
Member

image

It's working because there is no type check.

@RigottiG
Copy link

RigottiG commented Jul 5, 2022

I'm facing the same error

@mjnaderi
Copy link

mjnaderi commented Jul 5, 2022

Same issue here. I'm going to use 7.32.2.

@bluebill1049 bluebill1049 removed status: need more detail Please follow our issue template. status: under investigation aware of this issue and pending for investigation labels Jul 5, 2022
@niemyjski
Copy link

Same

@bluebill1049 bluebill1049 pinned this issue Jul 8, 2022
@bluebill1049 bluebill1049 unpinned this issue Jul 8, 2022
@react-hook-form react-hook-form locked as resolved and limited conversation to collaborators Jul 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
TS Typescript related issues
Projects
None yet
Development

No branches or pull requests

7 participants