I'm trying to compare lists using an extension method that calls a comparer like so:
type HasDiff<T> = (object: T, row: any) => boolean;
 export const isListEqualToRows = <T>(objects: T[], rows: any[], hasDiffFunction: HasDiff<T>): boolean => {
  if (objects.length !== rows.length)
    return true;
  return rows.every((row, index) => {
    const object = objects[index];
    if (row.isNew) {
      return false;
    }
    return !hasDiffFunction(object, row);
  });
};
The comparison is being triggered by Angular's value changed in a ReactiveForm, not sure if relevant, but here's it:
import { isListEqualToRows } from '@core/helpers';
formGroup.valueChanges.pipe(debounceTime(debounceValue)).subscribe((changes) => {
  this.areChangesDetected = !isListEqualToRows<Person>(this.items, changes, this.hasDiff);
});
My issue is that for one object, I have a list within a list. So I'm trying to call the isListEqualToRows() method again inside:
hasDiff(item: Person, row: any): boolean {
  return item.description !== row.description
    || !isListEqualToRows<Address>(item.addresses, row.addresses, this.hasDiffAddress);
}
hasDiffAddress(item: Address, row: any): boolean {
  return item.AddressId !== row.id
    || item.AddressStreet !== row.street;
}
But I end up getting this error while running the second line of the hasDiff() method:
Cannot read properties of undefined (reading 'hasDiffAddress')
How to solve this issue?
 
    