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

Deep partial update breaks build #58

Closed
kbrilla opened this issue Nov 18, 2020 · 12 comments · Fixed by #59
Closed

Deep partial update breaks build #58

kbrilla opened this issue Nov 18, 2020 · 12 comments · Fixed by #59

Comments

@kbrilla
Copy link

kbrilla commented Nov 18, 2020

I'm submitting a...


[x] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

interface FiltersForm {
  usersSelect: any;
  periodFrom: string;
  periodTo: string;
  dueDateFrom: string;
  dueDateTo: string;
}

 public readonly form: FormGroup<FiltersForm> = this.formBuilder.group<FiltersForm>({
    usersSelect: null,
    periodFrom: '',
    periodTo: '',
    dueDateFrom: '',
    dueDateTo: ''
  });

 this.form.patchValue({ usersSelect: null });

last line breaks build;

ERROR in filters.component.ts:120:7 - err
or TS2769: No overload matches this call.
  Overload 1 of 2, '(valueOrObservable: Observable<DeepPartial<ControlsValue<FiltersForm>>>, options?: Pick<ControlOptions, "onlySelf" | "em
itEvent"> | undefined): Subscription', gave the following error.
    Argument of type '{ usersSelect: null; }' is not assignable to parameter of type 'Observable<DeepPartial<ControlsValue<FiltersForm>>>'.
      Object literal may only specify known properties, and 'usersSelect' does not exist in type 'Observable<DeepPartial<ControlsValue<Filte
rsForm>>>'.
  Overload 2 of 2, '(valueOrObservable: DeepPartial<ControlsValue<FiltersForm>>, options?: Pick<ControlOptions, "onlySelf" | "emitEvent"> |
undefined): void', gave the following error.
    Type 'null' is not assignable to type 'DeepPartial<any> | undefined'.

120       this.form.patchValue({ usersSelect: null });
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

filters.component.ts:28:3
    28   usersSelect: any;
         ~~~~~~~~~~~
    The expected type comes from property 'usersSelect' which is declared here on type 'DeepPartial<ControlsValue<FiltersForm>>'

When change type of usersSelect to usersSelect: number | null; error disappears.

Expected behavior

Deep partials to work with any;
DeepPartial = any;

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Environment


Angular version: X.Y.Z


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

@NetanelBasal
Copy link
Member

@itayod

@NetanelBasal
Copy link
Member

@rafaelss95

@itayod
Copy link
Contributor

itayod commented Nov 19, 2020

Hi @criskrzysiu thanks for taking the time and open this issue, though I can not reproduce this error from your example above, could you please create some reproduction of it on stackblitz?

@rafaelss95
Copy link
Contributor

Hey @itayod I've created a PR to fix this: #59.

@itayod
Copy link
Contributor

itayod commented Nov 19, 2020

rafaelss95 I have seen but I am not sure if what exactly the problem is as I can not reproduce it myself

@rafaelss95
Copy link
Contributor

rafaelss95 commented Nov 19, 2020

I was able to reproduce in local environment. Btw, a good explanation on why we need using an exit conditional using recursive types is very well explained here.

@itayod
Copy link
Contributor

itayod commented Nov 19, 2020

@rafaelss95 I still couldn't reproduce it on my pc, might depend on the typescript's version? could you create a reproduction for that?

@rafaelss95
Copy link
Contributor

rafaelss95 commented Nov 19, 2020

Ok, here you go.

Current behavior:

Captura de Tela 2020-11-19 às 11 28 57

Expected behavior:
Captura de Tela 2020-11-19 às 11 29 57

@itayod
Copy link
Contributor

itayod commented Nov 19, 2020

thanks, @rafaelss95 seems like I was missing "strictNullCheck" flag in my reproduction...

@kbrilla
Copy link
Author

kbrilla commented Nov 19, 2020 via email

@vesrah
Copy link

vesrah commented Nov 19, 2020

I also ran into this issue today, thank you for looking into it so quickly.

@CesarD
Copy link

CesarD commented Nov 27, 2020

Just ran into this issue myself as well. It happens with latest version 1.4.4 but not with 1.4.3.
Calling .patchValue() with partial model on a FormGroup without defining any particular type (any).

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

Successfully merging a pull request may close this issue.

6 participants