question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

issue: `Control` type regression

See original GitHub issue

Version Number

7.33.1

Codesandbox/Expo snack

https://codesandbox.io/s/youthful-elion-r6wrtw?file=/src/App.tsx

Problem description

In our prod application, we have a SharedFields component that renders some standard fields that several forms use. In order to do this, we pass a control prop that we take from the result of each useForm() hook. Since we don’t know the exact form data type, we use Control<any> for this prop type. This was working fine up to 7.33.0, but now TS throws an error.

Steps to reproduce

  1. Go to App.tsx
  2. See the error on SharedFields control prop.

This same code example works fine up to 7.33.0.

Expected behaviour

Control type should be able to handle generic types.

What browsers are you seeing the problem on?

No response

Relevant log output

Type 'Control<FormValues, object>' is not assignable to type 'Control<any, any>'.
  The types of '_subjects.state' are incompatible between these types.
    Type 'FormStateSubjectRef<FormValues>' is not assignable to type 'FormStateSubjectRef<any>'.
      Type 'FormStateSubjectRef<FormValues>' is not assignable to type '{ readonly observers: Observer<Partial<FormState<any>> & { name?: string | undefined; }>[]; subscribe: (value: Observer<Partial<FormState<any>> & { ...; }>) => Subscription; unsubscribe: Noop; }'.
        Types of property 'subscribe' are incompatible.
          Type '(value: Observer<Partial<FormState<FormValues>> & { name?: string | undefined; }>) => Subscription' is not assignable to type '(value: Observer<Partial<FormState<any>> & { name?: string | undefined; }>) => Subscription'.
            Types of parameters 'value' and 'value' are incompatible.
              Type 'Observer<Partial<FormState<any>> & { name?: string | undefined; }>' is not assignable to type 'Observer<Partial<FormState<FormValues>> & { name?: string | undefined; }>'.
                Type 'Partial<FormState<FormValues>> & { name?: string | undefined; }' is not assignable to type 'Partial<FormState<any>> & { name?: string | undefined; }'.
                  Type 'Partial<FormState<FormValues>> & { name?: string | undefined; }' is not assignable to type 'Partial<FormState<any>>'.
                    Types of property 'errors' are incompatible.
                      Type 'FieldErrorsImpl<DeepRequired<FormValues>> | undefined' is not assignable to type 'FieldErrorsImpl<DeepRequired<any>> | undefined'.
                        Type 'FieldErrorsImpl<DeepRequired<FormValues>>' is not assignable to type 'FieldErrorsImpl<DeepRequired<any>>'.
                          Property 'otherField' is incompatible with index signature.
                            Type 'FieldError' is not assignable to type 'Merge<FieldError, FieldErrorsImpl<DeepRequired<any>>>'.
                              Property 'type' is incompatible with index signature.
                                Type 'LiteralUnion<"pattern" | "valueAsNumber" | "valueAsDate" | "setValueAs" | "disabled" | "required" | "min" | "max" | "maxLength" | "minLength" | "validate" | "value" | "shouldUnregister" | "onChange" | "onBlur" | "deps", string>' is not assignable to type 'Merge<FieldError, FieldErrorsImpl<DeepRequired<any>>> | undefined'.
                                  Type '"pattern"' is not assignable to type 'Merge<FieldError, FieldErrorsImpl<DeepRequired<any>>> | undefined'.ts(2322)

Code of Conduct

  • I agree to follow this project’s Code of Conduct

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
bluebill1049commented, Jul 29, 2022

I did a deeper look at this issue. This can not be resolved with the newly updated field errors type, you are skipping the type check for the control so you will have to simply set it to any.

0reactions
meotimdihiacommented, Aug 8, 2022

Hi, then how to solve this problem? I don’t understand what @bluebill1049 was talking about. There is my problem https://stackblitz.com/edit/next-typescript-pokptk-wuiput?file=pages%2Finput2.tsx,pages%2Findex.tsx I appreciate it if someone helps me to solve it. It took 5-6 hours, but I can’t fix it. I am not really good with Typescript.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Software regression - Wikipedia
A software regression is a type of software bug where a feature that has worked before stops working. This may happen after changes...
Read more >
Regression analysis with control variables
A major strength of regression analysis is that we can control relationships for alternative explanations. You've probably heard the expression "correlation ...
Read more >
Regression modelling and other methods to control confounding
Regression modelling and other methods to control confounding ... The problem of measurement error afflicts all types of analysis, including regression ...
Read more >
A Crash Course in Good and Bad Controls
The problem arises when an analyst needs to decide whether or not the addition of a variable to a regression equation helps getting...
Read more >
Choosing the Correct Type of Regression Analysis
There are numerous types of regression models that you can use. This choice often depends on the kind of data you have for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found