I have the simillar issue as here:
How do I resolve the error I am encountering using custom Validator syntax?
FormBuilder group is deprecated
I've read that Questions, but the issue still occurs in linter:
group is deprecated: This API is not typesafe and can result in issues with Closure Compiler renaming. Use the
FormBuilder#group
overload withAbstractControlOptions
instead. Note thatAbstractControlOptions
expectsvalidators
andasyncValidators
to be valid validators. If you have custom validators, make sure their validation function parameter isAbstractControl
and not a sub-class, such asFormGroup
. These functions will be called with an object of typeAbstractControl
and that cannot be automatically downcast to a subclass, so TypeScript sees this as an error. For example, change the(group: FormGroup) => ValidationErrors|null
signature to be(group: AbstractControl) => ValidationErrors|null
. (deprecation)
And here is my formBuilder:
registerForm = this._fb.group({
firstname: ["", [Validators.required]],
lastname: ["", [Validators.required]],
email: ["", [Validators.required, Validators.email]],
password: ["", [PasswordValidator.strength]],
confirmPassword: ["", [Validators.required]]
}, {
validator: PasswordValidator.confirmed("password", "confirmPassword")
});
And my validator:
export class PasswordValidator {
static confirmed = (controlName: string, matchingControlName: string) => {
return (formGroup: FormGroup) => {
const control = formGroup.controls[controlName];
const matchingControl = formGroup.controls[matchingControlName];
if (matchingControl.errors && !matchingControl.errors.confirmedValidator) {
return null;
}
if (control.value !== matchingControl.value) {
matchingControl.setErrors({ confirmedValidator: true });
return ({ confirmedValidator: true });
} else {
matchingControl.setErrors(null);
return null;
}
};
}
}
Any idea why? I'm returning the proper object. :/
validators
and notvalidator
– Dystrophyvalidator: PasswordValidator.confirmed("password", "confirmPassword")
– Dystrophyvalidators: [PasswordValidator.confirmed("password", "confirmPassword")]
– Dystrophyinterface AbstractControlOptions { validators?: ValidatorFn | ValidatorFn[] | null asyncValidators?: AsyncValidatorFn | AsyncValidatorFn[] | null updateOn?: 'change' | 'blur' | 'submit' }
This is directly from the docs. The interface hasvalidators
, notvalidator
– Dystrophy