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

V2 - Fully Typed Version [BREAKING_CHANGES] #23

Closed
NetanelBasal opened this issue Jul 6, 2020 · 1 comment
Closed

V2 - Fully Typed Version [BREAKING_CHANGES] #23

NetanelBasal opened this issue Jul 6, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@NetanelBasal
Copy link
Member

In the current version, we tried to provide the maximum typing functionality we could get to make the migration as seamless as possible.

In the next version, we want to add the following features:

  • Currently, when using get or getControl we need to infer the control type explicitly:
const profileForm = new FormGroup<Profile>({
  firstName: new FormControl(''),
  lastName: new FormControl(''),
  skills: new FormArray([]),
  address: new FormGroup({
    street: new FormControl(''),
    city: new FormControl('')
  })
});

const cityControl = profileForm.getControl('address', 'city') as FormControl<string>;

We need to use TS to automatically infer the type so that users can write:

const cityControl = profileForm.getControl('address', 'city');
  • Improving Validators' typings. It'll be great to add both the control value and errors type:
type Errors = {
  passwordMismatch: boolean;
}

const form = new FormGroup<ChangePasswordForm, Errors>({
  password: new FormControl(),
  repeatPassword: new FormControl()
}, 
{ validator });

// The signature of validator should automatically be:
function validator(control: FormGroup<ChangePasswordForm>): Errors | null {}
@NetanelBasal NetanelBasal added the enhancement New feature or request label Jul 6, 2020
@NetanelBasal NetanelBasal pinned this issue Jul 6, 2020
@NetanelBasal NetanelBasal changed the title V2 - Fully Typed Version [BREAKING_CHANGE] V2 - Fully Typed Version [BREAKING_CHANGES] Jul 6, 2020
@rafaelss95
Copy link
Contributor

Yes, I just faced problem with it today while migrating an app from Angular Reactive Forms to this lib. Sample of the problem:

Component:

this.formGroup = this.formBuilder.group<User>({
  address: this.formBuilder.group<Address>({
    street: '',
    city: ''
  })
});

HTML:

<!-- The same happens if you use `getControl` or `.controls.` as both return `AbstractControl`, 
        which it isn't accepted by `formGroup` `@Input`. -->
<app-custom-component
  [formGroup]="formGroup.get('address')"
></app-custom-component>
Type 'AbstractControl<Address>' is missing the following properties from type 'FormGroup': controls, registerControl, addControl, removeControl, and 3 more.

To make it work under strict we have to use $any(...)

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

No branches or pull requests

2 participants