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: invalid useFieldArray context type #7853

Closed
1 task done
TiagoSaAdvizr opened this issue Feb 18, 2022 · 1 comment · Fixed by #7856
Closed
1 task done

issue: invalid useFieldArray context type #7853

TiagoSaAdvizr opened this issue Feb 18, 2022 · 1 comment · Fixed by #7856
Labels
TS Typescript related issues

Comments

@TiagoSaAdvizr
Copy link

Version Number

7.27.0

Codesandbox/Expo snack

https://codesandbox.io/s/resolver-context-forked-m8rcrl

Steps to reproduce

Check line 38, the control cannot infer the context type.

Expected behaviour

Control should infer context type.

What browsers are you seeing the problem on?

Chrome

Relevant log output

Type 'Control<FormValues, { isValid: boolean; }>' is not assignable to type 'Control<FormValues, object>'.
  The types of '_options.resolver' are incompatible between these types.
    Type 'Resolver<FormValues, { isValid: boolean; }> | undefined' is not assignable to type 'Resolver<FormValues, object> | undefined'.
      Type 'Resolver<FormValues, { isValid: boolean; }>' is not assignable to type 'Resolver<FormValues, object>'.ts(2322)

Code of Conduct

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

Moshyfawn commented Feb 18, 2022

Possible regression, @bluebill1049?
It happened between v7.12.2 and v7.13.0-next.0.

The Control type accepts TContext extends object = object generic now

export declare type Control<TFieldValues extends FieldValues = FieldValues, TContext extends object = object> = {
    ...
    _updateProps: (props: UseFormProps<TFieldValues, TContext>) => void;
    ...
};

and useFieldArray doesn't pass it into the control

export declare type UseFieldArrayProps<TFieldValues extends FieldValues = FieldValues, TFieldArrayName extends FieldArrayPath<TFieldValues> = FieldArrayPath<TFieldValues>, TKeyName extends string = 'id'> = {
    ...
    control?: Control<TFieldValues>;
    ...
};

hence the

Type 'Resolver<FormValues, { isValid: boolean; }>' is not assignable to type 'Resolver<FormValues, object>'

@bluebill1049 bluebill1049 added the TS Typescript related issues label Feb 18, 2022
bluebill1049 added a commit that referenced this issue Feb 19, 2022
* 🐛 fix(useFieldArray): pass context type down to Control

Closes: #7845

* fix type error caused by context infer on control object

* fix useWatch api as well

* fix missing overload

* Revert "fix type error caused by context infer on control object"

This reverts commit 0de0a00.

* change TContext to type any instead of object

* remove breaking change context generic

* remove breaking change context generic

* update API extrator

* change to unknown instead of any

* Revert "change to unknown instead of any"

This reverts commit ec596c3.

Co-authored-by: Beier Luo <bluebill1049@hotmail.com>
bluebill1049 added a commit that referenced this issue Mar 13, 2022
* 🐛 fix(useFieldArray): pass context type down to Control

Closes: #7845

* fix type error caused by context infer on control object

* fix useWatch api as well

* fix missing overload

* Revert "fix type error caused by context infer on control object"

This reverts commit 0de0a00.

* change TContext to type any instead of object

* remove breaking change context generic

* remove breaking change context generic

* update API extrator

* change to unknown instead of any

* Revert "change to unknown instead of any"

This reverts commit ec596c3.

Co-authored-by: Beier Luo <bluebill1049@hotmail.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 11, 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

Successfully merging a pull request may close this issue.

3 participants