I've got this warning
group is deprecated: This API is not typesafe and can result in issues with Closure Compiler renaming. Use the
FormBuilder#groupoverload withAbstractControlOptionsinstead. Note thatAbstractControlOptionsexpectsvalidatorsandasyncValidatorsto be valid validators. If you have custom validators, make sure their validation function parameter isAbstractControland not a sub-class, such asFormGroup. These functions will be called with an object of typeAbstractControland that cannot be automatically downcast to a subclass, so TypeScript sees this as an error. For example, change the(group: FormGroup) => ValidationErrors|nullsignature to be(group: AbstractControl) => ValidationErrors|null.
How can I fix this code?
export function passwordMatchValidator(
group: AbstractControl
): { invalidRePassword: boolean } | null {
const passwordCtrl: AbstractControl | null = group.get('password');
const passwordConfirmCtrl: AbstractControl | null = group.get(
'passwordConfirm'
);
if (passwordCtrl && passwordConfirmCtrl) {
if (passwordConfirmCtrl.touched || passwordConfirmCtrl.dirty) {
if (passwordCtrl.value !== passwordConfirmCtrl.value) {
passwordConfirmCtrl.setErrors({ invalidRePassword: true });
return { invalidRePassword: true };
}
}
}
return null;
}
this.frm = this.fb.group({
password: ['', Validators.required],
passwordConfirm: ['', Validators.required],
},
{ validator: passwordMatchValidator }
);