After implementing the following validator, I encountered an error message.
The error states: "Expected 1 argument, but got 2 (ts 2554)."
Although many sources mention overloading as a common issue, there is no overload present in this case.
export const customValidatorAsync = (co: CustomObject, id: string): AsyncValidatorFn =>
return (control: AbstractControl): Promise<ValidationErrors | null> | Observable<ValidationErrors | null> => {
...
});
When incorporating it like so (this field is within a group of fields that users can add instances to):
setFieldValidators(index: number): void {
const array = <FormArray>objectRegistrationForm.controls["children"];
const group = <FormGroup>array.controls[index];
group.controls["field"].setValidators([
Validators.required,
Validators.maxLength(20)],
[customValidatorAsync(customObject, objectRegistrationToSave.children[index].id)]);
}
Previously, this validator did not require the id since user data was non-modifiable. However, currently, the data needs validation if it's being used by another object. Therefore, the current id is necessary (it will be empty when creating a new registration, allowing for a possible null value).
I have verified that the expected data is being received, but I am perplexed as to why this validator is now generating an error. When hovering over the import statement, it insists on two arguments instead of one.